The Earth’s atmosphere evolved along with the evolution of life. It’s composition has changed in response to the development of life over millions of years.
Today’s constitution is maintained by the larger metabolic processes of the planet, by which I mean things like weather patterns and ocean currents, and by the metabolic processes of the life the planet supports.
Until about 3.8 billion years ago, oxygen was scarce in Earth’s atmosphere, which was made up mainly of hydrogen, ammonia, methane and carbon dioxide. At this time, the end of the volcanic Hadean era, the Earth had cooled enough that water vapour, produced by ‘outgassing’ from volcanoes, condensed to form the oceans.
Once there were oceans, a certain amount of oxygen was produced by the action of ultraviolet light upon water molecules. This brought the oxygen level up to about 2% of what it is today.
This low level of oxygen was enough for life to begin, around 3 billion years ago. Amongst the earliest forms were the cyanobacteria, the first photosynthesizers. These exist in vast numbers in the fossil records. Photosynthesis depends upon the metabolisation of carbon dioxide and the transpiration of oxygen. These microscopic organisms changed the constitution of the air we breathe. Less carbon dioxide and more oxygen meant that correspondingly more life could be supported.
Before the extinction of the dinosaurs, there was a higher concentration of oxygen which supported much larger organisms, including plants, which photosynthesized accordingly.
Nowadays, the atmosphere is 21% oxygen, with carbon dioxide at 387 parts per million. The other main constituents of air are nitrogen at 79%, argon 1% and water vapour around 1%. All of these things are cycled through the living systems they are part of.
Water cycles through evaporation from the oceans and then condensation. It also cycles through living things. Carbon and oxygen, as we have seen, cycle mainly through metabolic processes of organisms. Nitrogen cycles almost exclusively through the action of bacteria. ‘Nitrogen fixing’ bacteria in the roots of some groups of plants, mostly but not exclusively legumes, take nitrogen which is inert in the soil and ‘fix’ it into the plant so that it becomes available to the atmosphere. Conversely, other bacteria break it back down into it’s inert state.
The air isn’t ‘formed’, it cycles. It’s modern constitution evolved along with, and in reponse to, the development of organisms. It is maintained by the biological processes of life on earth.