How Margaret Hamilton’s Computer Code Sent Humanity To The Moon

Published March 20, 2020

In 1969, NASA relied on software engineer Margaret Hamilton to safely land the Apollo 11 astronauts on the lunar surface — and to bring them back home.

Margaret Hamilton

Draper LaboratoryMargaret Hamilton stands next to the navigation software that her team designed for the Apollo mission.

Warning messages flashed on the screen at Mission Control on July 20, 1969. As the Apollo 11 lunar module — designated Eagle — descended toward the Moon’s surface, NASA had to decide whether to call off the historic mission. “With only minutes to spare,” software engineer Margaret Hamilton recalled, “the decision was made to go for the landing.” Moments later, Neal Armstrong landed the lunar module on the surface and stepped into history as the first man to walk on the Moon.

Hamilton was only 32 years old when she successfully led the MIT team that designed software for the lunar mission. Without her hard work and leadership, not only might the mission have failed but the three Apollo astronauts might even have been killed during the mission.

Who Was Margaret Hamilton?

Margaret Hamilton was born on August 17, 1936, in Paoli, Indiana. Her family later moved to Michigan and Hamilton attended the University of Michigan, Ann Arbor, for a time. She soon transferred, however, to Earlham College in Indiana where she graduated with a bachelor’s degree in mathematics, with a minor in philosophy.

In 1959, Margaret Hamilton took a job at MIT as a programmer working with Edward Norton Lorenz, the father of chaos theory. Hamilton was 24 years old and her husband had just enrolled at Harvard Law. While he spent three years in law school, Hamilton supported the family writing software and programming meteorological systems.

Margaret Hamilton In Her Office In 1989

NASAMargaret Hamilton in her office in 1989.

A few years later, Hamilton applied to work on a new project: writing the code that would put a man on the Moon. She was hired and became the first programmer brought on to the Apollo project. By 1965, Hamilton led a team of programmers at MIT’s Draper Laboratory.

As part of the Apollo project, Hamilton designed the onboard flight software for the historic Apollo 11 mission. “I was attracted both by the sheer idea and the fact that it had never been done before,” Hamilton explained. “I was the first programmer to join and the first woman they hired.”

Hamilton stood out on the Apollo project. She wasn’t just a woman – unusual enough at the time – she was also a working mother. When she worked in the lab on nights and weekends, she often brought her young daughter Lauren with her.

“People used to say to me, ‘How can you leave your daughter? How can you do this?'” Hamilton later recalled.

How Hamilton Wrote The Code That Brought Humanity To The Moon

Margaret Hamilton Apollo

NASAHamilton exploring the Apollo Command Module.

Originally, NASA didn’t predict the Apollo mission would require elaborate software. According to MIT professor David Mindell, “Software was not included in the schedule, and it was not included in the budget.”

Soon, NASA realized the mission would fail without the right software and by 1968, over 400 programmers were working on Hamilton’s software team. The team wrote and tested software for two Apollo computers: one on the command module and another for Eagle, the lunar module that would bring the astronauts to the lunar surface.

If disaster struck with all eyes on the Apollo mission, the blame might fall on Hamilton. One time, late at night after a party, Hamilton suddenly realized that part of her code was wrong and rushed to the lab. “I was always imagining headlines in the newspapers, and they would point back to how it happened, and it would point back to me.”

Creating software programs for a space mission wasn’t easy in the 1960s. Hamilton and her team wrote out code by hand on sheets of paper, then used a keypunch machine to punch holes into paper cards that were fed into the computer which would read these cards as instructions.

After testing their punch card code on an enormous Honeywell mainframe computer to work out any bugs on a simulated lunar landing, the code was than shipped off to a nearby Raytheon factory. There, women physically wove the program’s 0s and 1s through magnetic rings that represented the program’s 1s and 0s — a copper wire through a ring meant 1, going around the ring meant 0.

Apollo Guidiance Computer Ferrit Core Memory

Wikimedia CommonsHand-woven ferrite core memory as used in the Apollo Guidance Computer. The way the copper wires wound themselves through the magnetic rings of the memory represented the actual guidance software code used to fly to the Moon, land on the surface, and return to Earth.

The women, affectionately called the “little old ladies,” were expert seamstresses and their rope created a hardwired code for the modules that was effectively indestructible and impossible to erase.

The Apollo computers had to calculate guidance equations from space or the mission would be doomed. The computer had about 72 kilobytes of memory – less than one-millionth of the capacity of a modern cellphone. It could store 12,000 bits — representing a 1 or a 0 — in the copper rope memory but only 1,000 bits in its temporary working memory.

Don Eyles worked on the project at MIT. “We showed that that could be done,” he said. “We did it in what today seems an incredibly small amount of memory and very slow computation speed.”

How Hamilton’s Daughter May Have Saved The Apollo 11 Mission

Buzz Aldrin On The Moon

Neil Armstrong/NASAA photograph by Neil Armstrong shows Buzz Aldrin on the Moon.

Margaret Hamilton brought a unique background to her role. And while bringing her daughter Lauren to the lab made Hamilton stand out, it also helped save the mission.

One day, Lauren pushed a button on a simulator and crashed the system Hamilton was testing. Simply by pressing a pre-launch button during flight, Lauren erased the navigation data from the system’s memory.

“I thought: my God – this could inadvertently happen in a real mission,” Hamilton remembers. But when she recommended a change to the program, NASA responded, “Astronauts are trained never to make a mistake.”

Yet on the very next mission, astronaut Jim Lowell made the same error.

Hamilton called it “the Lauren bug” and remembers, “It created much havoc and required the mission to be reconfigured. After that, they let me put the program change in, all right.”

The Warning Messages That Nearly Doomed The Eagle Landing


NASAAt the Kennedy Space Center, NASA employees watch the Apollo 11 takeoff.

On the Apollo 11 mission, Margaret Hamilton watched as the software designed by her team guided astronauts Neil Armstrong and Buzz Aldrin toward the Moon’s surface.

But in one heart-stopping moment, warning messages flashed on the computer. In that instant, Hamilton felt confident in her software. “It quickly became clear that the software was not only informing everyone that there was a hardware-related problem, but that the software was compensating for it,” Hamilton explained.

Hamilton added, “Fortunately, the people at Mission Control trusted our software.”

Lunar Module

Michael Collins/NASAA view of the lunar module as it descended toward the Moon’s surface.

With only 30 seconds of fuel remaining in the module, Neal Armstrong’s voice reported back to mission control, “The Eagle has landed.”

From MIT, Hamilton remembers watching the historic moment she helped make possible. “My God. Look what happened,” she thought. “We did it. It worked.”

As for the warning message, Hamilton’s team learned their program worked exactly as designed. During the descent, a radar switch in the wrong position triggered the warning. The software restarted and focused on the highest priority task: landing the lunar module. Without the error detection and recovery mechanisms written by Hamilton, the mission would have failed.

“It was a total relief when they landed,” Hamilton said. “Both that the astronauts were safe, and that the software worked perfectly.”

“There Was No Choice But To Be Pioneers”

Hamilton Medal Of Freedom

Lawrence Jackson/The White HouseIn 2016, President Obama presented Hamilton with the Presidential Medal of Freedom.

In 2016, President Barack Obama awarded Margaret Hamilton the Presidential Medal of Freedom. “Our astronauts didn’t have much time,” Obama said, “but thankfully they had Margaret Hamilton.”

When Hamilton took over the software team working on the Apollo 11 mission, one of her bosses worried that the men on Hamilton’s team might rebel. “Well, they didn’t,” Hamilton quipped.

In Hamilton’s words, on the Apollo 11 mission “there was no choice but to be pioneers.”

Fascinated by the 1960s space missions? Relive the experience with vintage NASA photos and then learn the behind-the-scenes history of the Apollo 11 mission.

Genevieve Carlton
Genevieve Carlton is a freelance writer with a Ph.D in history.