McNamara was born in San Francisco into an Irish family. He graduated from high school in 1933. McNamara was an Eagle Scout. He went to the University of California Berkeley where he got a degree in economics. He went to Harvard University for his MBA. After a short time working as an accountant he taught at Harvard. He married his high school sweetheart, Margaret Craig, in 1940. In 1943 he joined the Air Force. During the war, he looked at how effficent bombers were working and rose to the rank of lieutenant colonel. For his service in World War II, he was given the Legion of Merit.