The Earth formed approximately 4.6 billion years ago.Ideas about how the atmosphere was produced and has changed have developed over time as new evidence has been discovered.
The early atmosphere came from intense volcanic activity, which released gases such as: Carbon Dioxide, Oxygen, Ammonia, and Methane.
Volcanic activity also released water vapour which condensed to form oceans and seas. The water began dissolving Ammonia - creating Ammonia compounds and Nitrogen - containing substances. Nitrogen was most likely stored in the atmosphere as it is so unreactive.
2.7 billion years ago, plants and algae began to build up in the oceans so Carbon Dioxide decreased in the atmosphere (carbon sink) as it was being used in photosynthesis. Oxygen levels increased because it was released from the plants and into the atmosphere.
Oxygen being in the atmosphere enabled animals to evolve, increasing Carbon Dioxide levels so it could be used in photosynthesis. The ozone layer prevented lots of UV light getting through so land animals and plants could form.
Today we burn fossil fuels which increase CO2 levels faster than it can be removed. We keep cutting down trees & killing plants, decreasing the amount of C02 being used in phtosynthesis.