The gravitational force of Earth is sufficient to trap gases and particles around the planet.
Without this gravity, the atmosphere would never have formed, as its components would have gone flying off into space.
The Earth’s second atmosphere was formed about 3.4 billion years ago, with nitrogen being the major component.
During the same period, the continents formed which allowed the transfer of carbon dioxide to large land-based carbonate storages.
Oxygen in the earth’s atmosphere did not exist until about 1.7 billion years ago when levels fluctuated until reaching a steady state of more than 15%.
It was during the Phanerozoic era shortly after, that oxygen-breathing metazoan life forms began to appear.