Science & Tech

When the computer cried for help during the Moon landing, Margaret Hamilton's code saved the day

Two hundred and fifty thousand miles from home, with the lunar module dropping toward the surface and the whole world watching, the computer flying Apollo 11 suddenly flashed an alarm, and then another. For a few terrible seconds it looked as if the first Moon landing might have to be called off. It was not, and the reason was a quiet decision made years earlier in the software written by a young woman in Cambridge, Massachusetts.

A woman scientist in the 1960s standing beside a stack of printed Apollo source code as tall as she is, evoking Margaret Hamilton

Margaret Hamilton beside a listing of the Apollo flight software her team wrote, famously as tall as she was. Illustration: Watts & Wild.

Margaret Hamilton led the team at the Massachusetts Institute of Technology that wrote the on-board flight software for the Apollo Guidance Computer, the small machine that steered the spacecraft. She was a working mother in her early thirties, sometimes bringing her young daughter to the lab at night, and she was helping invent a kind of engineering that did not yet have a name.

The story of those alarms over the Moon is really the story of how good software is supposed to behave when everything goes wrong at once, and of a person who insisted on planning for exactly that.

The computer that flew to the Moon

By today's standards the Apollo Guidance Computer was almost laughably feeble. It had a tiny fraction of the memory of a cheap modern phone, ran far slower than a basic calculator, and its core program was literally woven by hand. The software was threaded into rope memory, with wires passed through or around tiny magnetic rings to spell out ones and zeros, a physical fabric of code that could not be changed once made.

That this fragile-sounding machine guided human beings to another world at all is remarkable. It worked because the people who programmed it could not rely on raw power, so they had to be ruthlessly clever about how it spent every scrap of attention it had.

Twelve-oh-two: the alarm that nearly aborted the landing

As the lunar module Eagle descended on 20 July 1969, the computer flashed a code: 1202. Moments later it threw another, 1201. Neither astronaut knew offhand what they meant, and in Mission Control a roomful of engineers had only seconds to decide whether to wave the crew on or order them to abort and turn back. The codes meant the computer was overloaded, being asked to do more work than it possibly could in the time it had.

The cause turned out to be a small human slip. A checklist had the astronauts leave a radar switch in the wrong position, and that radar was bombarding the computer with extra work it did not need during landing, stealing precious processing time many times a second. The machine was drowning, and the most famous landing in history hung on what it would do next.

A close-up of the Apollo Guidance Computer and its hand-woven core rope memory of wires and magnetic rings
The program lived in rope memory, woven by hand from wire and tiny magnetic cores. Illustration: Watts & Wild.

Why Margaret Hamilton's software refused to crash

Here is the heart of it. Hamilton's team had not written software that simply tried to do everything and froze when it could not. They had built it to know the difference between what mattered and what did not. Every task was given a priority, and if the computer was ever swamped, it would shed the unimportant jobs, restart, and rebuild itself around the few things that truly counted, like steering the descent and firing the engine.

So the 1202 alarms were not the computer failing. They were the computer coping, exactly as designed, throwing away the radar busywork and protecting the landing. In Mission Control the engineers who understood this gave the call to go, and minutes later Neil Armstrong set Eagle down with seconds of fuel to spare. The alarm that looked like a disaster was in fact the software doing the cleverest thing it knew how to do.

The woman who named software engineering

At the time, writing code was not taken very seriously next to the glamour of rockets and hardware. Hamilton pushed back on that, insisting her work was a true engineering discipline, and she helped popularise the very term software engineering to make the point. Today every app, car and aircraft runs on the idea she fought to legitimise, that software must be built with the same rigour as the machines it controls.

For decades she was a footnote to the men who flew, but recognition came eventually. There is a famous photograph of her standing next to a stack of the Apollo code printouts taller than she is, and in 2016 she received the Presidential Medal of Freedom for work that helped carry humans to the Moon and bring them home.

The Apollo lunar module descending toward the grey cratered surface of the Moon in 1969
Eagle landed with seconds of fuel left, its computer still flashing and still flying. Illustration: Watts & Wild.

The honest catch

The neat headline, that one woman's code saved Apollo 11, flattens a richer truth. Hamilton led a large team, and the clever scheduling design built on ideas from other engineers at the lab, while the rope memory itself was woven by skilled factory workers, mostly women, whose names we mostly do not know. The quick, correct go call in Mission Control was its own act of nerve. Many hands kept Eagle in the sky.

But leadership and design matter, and the decision to build software that fails gracefully rather than catastrophically was central, and it was hers to champion. The lasting lesson is almost gentle: the strongest systems are not the ones that never hit trouble, but the ones that know what to let go of when trouble comes. A computer the size of a suitcase taught us that on the way to the Moon.

Ad slot (AdSense auto ad will appear here once approved)

A computer weaker than a toy guided people to the Moon, and survived its scariest moment because someone had taught it what to ignore. Do we still build our systems, and our lives, to fail this gracefully? Tell us what you think in the comments.

Related reading: the Voyager Golden Record, humanity's message still flying out of the solar system.

More from Watts & Wild

More in Science & Tech →

The big energy stories, once a week

No spam. Just the most interesting things happening in energy, engineering, and the natural world.