At Christmas 1968 the crew of Apollo 8, the first astronauts to orbit the Moon, faced a computer crisis. The data needed to get them back to Earth had disappeared from their onboard navigation system.
But Margaret Hamilton, who led software development for the Apollo guidance computer, came to the rescue. She knew what had gone wrong because her four-year-old daughter Lauren had triggered the same error while playing with a flight simulator in her lab at the Massachusetts Institute of Technology. Like little Lauren, Apollo 8 astronaut Jim Lovell mistakenly activated a programme not designed for use in flight.
Hamilton, who has died aged 90, guided Nasa controllers to correct what she called the “Lauren bug”. She later recalled that Nasa could have avoided the emergency by heeding her advice, but, as she told the US Computer History Museum in 2017, the agency resisted doing so “because they were worried about extra code — and astronauts never, ever make a mistake”. The bug was immediately fixed for subsequent missions.

“To say Margaret Hamilton was a pioneer — to say she was ahead of her time — would be a dramatic understatement,” said Olivier de Weck, Apollo programme professor of astronautics at MIT.
“She was a software engineer at a time when that field was in its infancy, and she not only developed advanced code herself but also led a team in using that nascent technology to develop one of the most complex systems humanity had ever achieved,” de Weck added.
She went on to found and run two research-oriented companies, Higher Order Software in 1976 and Hamilton Technologies in 1986, which specialised in developing computer systems with error prevention as a priority.
Margaret Heafield was born in 1936 in Paoli, Indiana, the daughter of a schoolteacher and a professor. She grew up in the Midwest and studied maths at the University of Michigan and Earlham College. She married James Cox Hamilton, a fellow student at Earlham, after graduating in 1958.
In 1959 she joined the MIT lab of renowned meteorology professor Edward Lorenz. Hamilton helped Lorenz to simulate and predict the weather, learning the essentials of programming on the job. Their research laid the foundations for Lorenz to develop his “chaos theory”, including the famous “butterfly effect” in which a tiny change in starting conditions triggers a huge divergence of outcomes in a non-linear system such as the atmosphere.
In 1961 Hamilton transferred to an MIT team working on software for Sage, the first computerised US air defence system. She joined the Apollo programme in 1965 at the MIT Instrumentation Lab, which had won a Nasa contract. By 1968 she had been promoted to lead the team programming the onboard guidance computers that the astronauts used to navigate in space.

“The programmers . . . would write things by hand on coding sheets,” she later recalled. “Then we would give them to keypunchers who would punch them [on data cards].” A widely reproduced photograph showed Hamilton standing next to a pile of coding paper that reached as high as her head.
In July 1969, when the Apollo 11 mission was minutes away from the first manned landing on the Moon, the onboard computer flashed code 1201 and 1202 alarms. They indicated an overload that might interfere with the complex touchdown sequence.
Fortunately Hamilton and colleagues had engineered the software to dump non-essential background tasks under those circumstances and prioritise procedures needed for the landing. Nasa controllers in Houston trusted the software, so they decided not to abort the mission, allowing Neil Armstrong and Buzz Aldrin to touch down safely in their Eagle module.
Hamilton actively promoted herself as a software engineer, in an effort to correct the widespread impression at the time that programmers were “second-class citizens” in contrast to the hardware developers who were real engineers, she told the Computer History Museum. “There’s Margaret again with her software engineering,” MIT colleagues would joke — but she would live to see software achieve equal status with hardware development.
“Hers was a career dedicated to preventing errors and what she called ‘handling the unknown’,” said MIT’s de Weck. “She personified leadership by example and established a practice of software engineering based on problem-solving and systems engineering that we all benefit from.”