Computer pioneer Margaret Hamilton was critical to landing astronauts on the moon for the first time on 20 July 1969 and returning them safely a few days later. The young Massachusetts Institute of Technology (MIT) computer programmer and working mother led the team that created the onboard flight software for the Apollo missions, including Apollo 11. The computer system was the most sophisticated of its day. Her rigorous approach was so successful that no software bugs were ever known to have occurred during any crewed Apollo missions. “She symbolises that generation of unsung women who helped send humankind into space,” said President Barack Obama in 2016 when he awarded Hamilton the Presidential Medal of Freedom, the United States’ highest civilian award. In 2017, she was one of a handful of Nasa women to be immortalised as a Lego figurine.On the 50th anniversary of the first moon landing, Hamilton, 82, looks back on her trailblazing work in computing.

What got you into software engineering? There were no computer science degrees when you were starting out…

I got married in 1958, just after I graduated in math with a minor in philosophy from Earlham College [in Indiana]. We both had assistantships to attend graduate school – me in abstract math and my husband in chemistry – but in the meantime I had taught high school for a year, we had my daughter, and my husband decided he wanted to go to law school at Harvard. I found a job to support our family at the nearby Massachusetts Institute of Technology (MIT). It was in the laboratory of Prof Edward Lorenz, the father of chaos theory, working on a system to predict weather. He was asking for math majors. To take care of our daughter, we hired a babysitter. Here I learned what a computer was and how to write software. Computer science and software engineering were not yet disciplines; instead, programmers learned on the job. Lorenz’s love for software experimentation was contagious, and I caught the bug.

I was fortunate to have a very modern husband. There were some men who understood equality

How did you end up joining the Apollo project in 1964?

I had moved to writing software for detecting enemy aircraft at MIT’s Lincoln Laboratory. I was planning to resume graduate school when my husband saw a newspaper advert. The MIT Instrumentation Laboratory was looking for people to develop software to “send man to the moon”. The lab had received the Nasa contract to build the onboard flight software for the Apollo project, having already been selected to design the computer hardware. I was attracted both by the sheer idea and the fact that it had never been done before. I was the first programmer to join and the first woman they hired. Male engineers were already working on the project, but they were hardware engineers and it wasn’t their thing. I had it as my background. I think [the lab] just figured that I could handle the unknown.

You first worked on the software for the unmanned Apollo missions. But you were gradually promoted to lead the team developing the software for the manned spacecraft, including Apollo 11. What did your job entail?

There were two onboard computers – one on the command module, Columbia, and one on the lunar module, Eagle. Our task included developing the software to run on each and the systems software they shared. At the beginning, nobody thought software was that big a deal. But then they began to realise how much they were relying on it. The group grew so there were approximately 100 software engineers on my team. Astronauts’ lives were at stake. Our software needed to be ultra-reliable and it needed to be able to detect an error and recover from it at any time during the mission. And it all had to fit on the hardware.

Margaret Hamilton in 1969 with the source code her team developed for the Apollo missions. Photograph: Science History Images/Alamy Stock Photo

Did your life as a software engineer and a mother ever collide?

Often in the evening or at weekends I would bring my young daughter, Lauren, into work with me. One day, she was with me when I was doing a simulation of a mission to the moon. She liked to imitate me – playing astronaut. She started hitting keys and all of a sudden, the simulation started. Then she pressed other keys and the simulation crashed. She had selected a program which was supposed to be run prior to launch – when she was already “on the way” to the moon. The computer had so little space, it had wiped the navigation data taking her to the moon. I thought: my God – this could inadvertently happen in a real mission. I suggested a program change to prevent a prelaunch program being selected during flight. But the higher-ups at MIT and Nasa said the astronauts were too well trained to make such a mistake. Midcourse on the very next mission – Apollo 8 – one of the astronauts on board accidentally did exactly what Lauren had done. The Lauren bug! It created much havoc and required the mission to be reconfigured. After that, they let me put the program change in, all right.

The astronauts get most credit for landing on the moon. But they did it with help from a system you created to warn of inflight emergencies. As President Obama put it: “Our astronauts didn’t have much time, but thankfully they had Margaret Hamilton.”

Just as the astronauts were about to land, the software’s priority displays interrupted them with alarms to warn there was an emergency, and that the computer was overloaded. I learned about it as it was happening, standing in the monitoring room at MIT. We pieced together afterwards what had happened, which was that a radar switch was in the wrong position and it was taking up processing power. It quickly became clear the software was not only informing everyone that there was a hardware-related problem but was compensating for it – restarting and re-establishing the highest priority tasks. The error detection and recovery mechanisms had come to the rescue. It was a total relief when they landed – both that the astronauts were safe, and that the software worked perfectly.

Don’t be afraid to say 'I don't know'. No question is a dumb question

As I understand things, in the early days of computer programming, women were actually quite well represented. It was sort of considered women’s work. Is that your experience?

Programming was never considered to be women’s work, at least not in any of the many projects I have been involved with. Human computers [who did calculations by hand] were mostly all women and there were women who used calculating machines – like the Marchant machines – but they weren’t programmers. They didn’t write software. When I first came to Apollo, there were no other women writing software. Then within a couple of years there would be a few – and I did have some working for me – but not many. There were always many more men.

Were the men bothered by you being their boss?

When I took over, one of the bosses at the top said he had no doubt I could do the job but was worried the men working in the group might rebel. Well, they didn’t. More than anything, we were dedicated to the missions and worked side by side to solve the challenging problems and to meet the critical deadlines. I was also fortunate to have a very modern husband, especially for that time. There were some men who understood equality.

You invented, or at the very least, popularised the term “software engineering”. Why did it need a new name?

During the early days of Apollo, software was not taken as seriously as other engineering disciplines. Though in fact we had a complex system of systems, we weren’t getting credit for what was a legitimate field. It was out of desperation I came up with the term, to say: “Hey, we’re engineering too.” It was an ongoing joke for a long time. Then one day in a meeting, one of the most respected hardware gurus explained to everyone that he agreed with me. The process of building software should also be considered an engineering discipline, just like with hardware. It was a memorable moment.

Margaret Hamilton immortalised in Lego as part of the Women in Nasa series. Photograph: Courtesy of Lego

After Apollo, parts of your code went on to be used in Skylab, the first space station, and then in the space shuttle programme. You went on to found your own businesses, using your experience to design software to be more reliable and affordable. What are the lessons of the Apollo project for programmers today?

We’ve recently seen systems where a plane crashed and the pilot had no idea what was going on. It’s a good idea for the pilot to know what their options are! Also, what became apparent with Apollo – though it is not how it worked – is that it is better to define your system up front to minimise errors, rather than producing a bunch of code that then has to be corrected with patches on patches. It’s a message that seems to have gone unheeded – in this respect, software today is still built the way it was 50 years ago.

There is a famous photograph taken of you in 1969 standing next to a stack of printed code from the Apollo missions that is almost taller than you. Recently that image was juxtaposed next to one of Katie Bouman, the scientist who helped develop the algorithm that created the first ever image of a black hole. She is posing with a stack of her project’s hard drives, and the montage went viral. Do you remember your picture being taken and what did you make of the comparison?

The photograph was taken during the Apollo 11 mission by an MIT photographer to send out to newspapers. We got carried away and grabbed all the Apollo listings in my office and created the tower. I was trying to find a way of keeping the stack up. I didn’t look at the comparison as a bad thing. At least they aren’t hiding us. Though I don’t envy [Bouman] having to contend with the internet and all the vitriol it can spread. In some ways, things are worse for women now.

What advice would you give young women who want a career in coding?

Don’t let fear get in the way and don’t be afraid to say “I don’t know” or “I don’t understand” – no question is a dumb question. And don’t always listen to the so-called experts!