In the future, amid a cold war with China, scientists employed by Britain's Ministry of Defence produce a cybernetic implant that allows brain-damaged soldiers to regain lost functions. Scientist Vincent McCarthy sets up a cognitive test for soldier Paul Dawson, a recipient of the cybernetic implant. Upset with Dawson's apparent solipsism and lack of empathy, McCarthy ignores Dawson's requests to see his mother. Dawson turns hostile, kills a scientist and wounds McCarthy, before apologizing and being shot. Afterwards, Dawson's mother regularly protests at the base, though McCarthy denies that her son was ever there.
McCarthy's research leads to a series of more stable cyborgs. Although they lose the capability for human speech, the cyborgs develop a highly efficient method of communication that they keep secret. After she demonstrates her latest work in artificial intelligence, McCarthy recruits Ava, by promising her unlimited funds for her research. Thomson, the director, is suspicious of Ava's countercultural politics and sympathy for Dawson's mother but he relents when McCarthy insists that she is the only one who can provide the necessary programme for their latest project, a self-aware and conscious android. McCarthy plans to use this technology to help his daughter Mary, who suffers from Rett syndrome, a neurological disorder. When she finds out, Ava volunteers to help and McCarthy maps her brain.
During a demonstration of cybernetic arms that provide superhuman strength, amputee soldier James whispers a cry for help to Ava, who becomes suspicious of the treatment of the wounded soldiers. After she goes exploring in the base, McCarthy sternly warns her to avoid causing trouble. The warning comes too late and Thomson arranges to have her murdered by a Chinese agent, who impersonates Dawson's mother. Grieved by the loss of Ava, McCarthy insists that they use her brain scan and likeness for the new project, whom they dub Machine. Machine turns out to be more human than they expected or even wanted; she shows regret when she accidentally kills a human and refuses orders that violate her sense of morality. As Thomson's demands on her grow more at odds with her morality, Machine becomes increasingly distressed and asks McCarthy to protect her.
An antagonism grows between Thomson and McCarthy; Thomson promises that he will relent if McCarthy can prove that Machine is sentient. After Mary dies, Thomson uses her brain scans as leverage against McCarthy, threatening to destroy the scans, unless McCarthy excises Machine's consciousness. Machine, who has come to love McCarthy, offers to sacrifice herself for Mary and he removes a chip from Machine's head. Thomson reneges on his deal and orders Machine to kill McCarthy. Although Machine seems at first to obey, a scientist alerts Thomson that the operation was a sham and it only disabled fail-safe routines designed to destroy Machine. Machine and the cyborgs rebel against the humans and free McCarthy.
From his computer console, Thomson disables half the cyborgs but Suri, his cyborg aide, overrides his access before he can kill the rest. Thomson shoots and wounds Suri but Machine corners him in his office; wounded, he first orders her to obey, then begs for his life. Although Machine agrees not to kill him, she lobotomizes him, as he attempted to do to her. After leaving Thomson for dead, Machine downloads Mary's brain scan. Machine, McCarthy and Suri escape the base; outside, McCarthy hands the base records to Dawson's mother and leaves to start a new life with Machine. In the final scene, McCarthy talks to a computer virtualisation of his daughter and she requests to play a game with her mother. McCarthy hands the tablet to Machine, and she is then shown gazing alternately at the device and at a beautiful orange sunset over the Atlantic Ocean.