In the first billion years of Earth's history, the surface was covered with Volcanoes that erupted and let out lots of gas, which is how the early atmosphere was formed
It was probably mostly carbon dioxide, with virtually no oxygen.
volcanic activity released nitrogen, which built up in the atmosphere over time, as well as water vapour and small amounts of Methane and ammonia
phase 2 - oceans, algae and green plants absorbed carbon dioxide
when the water vapour in the atmosphere condensed, it formed the oceans
Lots of CO2 was removed from the early atmosphere as it dissolved in the oceans. this dissolved CO2 the formed carbonate precipitates that formed sediments on the seabed
Green plants and algae evolved and absorbed some of the CO2 so that they could carry out photosynthesis. When marine animals evolved their Shells contained carbonates from the oceans
phase 3 - green plants and algae produced oxygen
As oxygen levels built up in the atmosphere, more complex life could evolve
Eventually, about 200 million years ago, the atmosphere reached the composition of 80% nitrogen, 20% oxygen and small amounts of other gases
Greenhouse effect
The process by which greenhouse gases in the atmosphere absorb and trap long wavelength radiation emitted from the Earth's surface, causing the temperature of the atmosphere to increase