A man wakes up on a train at 7:40AM sitting across a woman named Christina Warren. The woman knows him by the name Sean Fentress, but he doesn't know her and appears uncertain of his own identity. After eight minutes, a bomb goes off on the train, and the man awakens to find himself strapped inside a small geodesic dome. There, Air Force Capt. Colleen Goodwin explains to him through a computer screen that he is actually Colter Stevens, a decorated army helicopter pilot, now on a mission to locate the maker of a bomb which destroyed a train headed into Chicago. This is to be accomplished using the Source Code which is a time loop program that allows him to take over someone's body in a reenactment of their last eight minutes of life.
Stevens is sent into the Source Code repeatedly, and each time a series of events repeat, with variations due to Stevens' acts. Meanwhile, he goes on searching for the terrorist and getting to know Christina, until the bomb that destroys the train goes off and Fentress dies, sending Stevens back to the chamber. He is unwillingly sent back into the Source Code again and again in frustrating, exhausting attempts to learn the bomber's identity. He tries to warn authorities on the train and escape with Christina, escaping the explosion. Other times he can’t locate or disarm the bomb and dies on the train. But Rutledge insists the alternate timeline is not real. It is revealed that he has been with them for two months since being reported killed in action in Afghanistan. He is comatose and missing most of his body, hooked up to neural sensors. The cockpit capsule is in his imagination, his brain's way of making sense of a missing environment. A confused and frustrated Stevens asks, "As one soldier to another, am I dead?" He is angry to know that he is on life support and he ask to disconnect him after the mission.
Stevens catches the bomber Derek Frost, who leaves his wallet behind to fake his own death, and gets off at the last stop before Chicago. In one run-through, Frost kills both Fentress and Christina, and flees in a rented white van. Stevens remembers the license number and direction so the authorities can catch the terrorist. Rutledge orders Goodwin to wipe Stevens' memory for a future mission. Stevens convinces Goodwin to allow to try it again to save everyone on the train despite Rutledge's insistence that everyone on the train had already been killed in the explosion.
While he is on the train using a cellular phone, Stevens discovers that he supposedly died two months ago. He confronts Goodwin with what he knew, and discover it from Goodwin and Rutledge that he had been shot down during the war, and his mutilated body was appropriated by the Air Force and used by Rutledge to operate the Source Code. Stevens then asks Rutledge and Goodwin to let him die, which they promise they will do once the mission is finished. After the mission accomplished, and despite their promise, Rutledge orders Stevens' memory to be erased and stored for reuse in further missions. However, Stevens persuades Goodwin to send him in one more time and give him one last chance to avert the train disaster. Goodwin agrees that he deserves to be allowed to die in peace afterwards instead of being held alive as a military brain in a vat.
Later that morning, the alternative-timeline Captain Goodwin arrives for work at Nellis Air Force Base and receives the email from Stevens. While news breaks about the failed bomber on the Chicago train, he informs Goodwin that they have changed history, and Goodwin seemingly recalls something. He asks her to reassure this timeline's Stevens that "everything is gonna be okay."