Terrestrial planet formation is generally thought to have proceeded in two main stages: The first consists of the accretion of planetesimals, which leads to the formation of several dozens of roughly Mars-sized planetary embryos, and the second stage consists of a series of giant impacts between these embryos that merge to form the Earth and other terrestrial planets. Understanding how much of the planets’ primordial atmosphere is retained during the giant impact phase is crucial for understanding the origin and evolution of planetary atmospheres. In addition, a planet’s or protoplanet’s atmosphere cannot only be lost in a giant impact, but also due to much smaller impacts by planetesimals. Therefore, in order to understand the origin and evolution of the terrestrial planets’ atmospheres I will examine the contributions to atmospheric loss from both giant impacts and from planetesimal accretion and show that planetesimal impacts are likely to dominate the atmospheric mass loss during planet formation. I will discuss the implications of these findings for the formation of the terrestrial planets and their volatile budgets.