It is difficult to understand completely how the Earth's atmosphere has changed over time as we are looking for evidence which is limited due to the large timescales of 4.6 billion years.
One theory suggests that during the first billion years of the Earth’s existence there was intense volcanic activity that released gases that formed the early atmosphere and water vapour that condensed to form the oceans.
At the start of this period the Earth’s atmosphere may have been like the atmospheres of Mars and Venus today, consisting of mainly carbon dioxide with little or no oxygen gas.
Volcanoes also produced nitrogen which gradually built up in the atmosphere and there may have been small proportions of methane and ammonia.
Later, as the Earth's temperature cooled, this water vapour turned to rain forming the oceans, The carbon dioxide present in the atmosphere dissolved in the water producing carbonates which were precipitated producing sediments. This would ultimately reduce the amount of carbon dioxide in the atmosphere.
How oxygen increased
The emergence of algae around 2.7 billion years ago produced oxygen into the atmosphere. Over the next billion years as plants evolved the percentage of oxygen gradually increased to levels that would allow animals to evolve.
The algae and plants produce oxygen by photosynthesis, which can be represented by the equation:
Carbon dioxide + Water --> Glucose + Oxygen
How carbon dioxide decreased
The algae and plants also decreased the percentage of carbon dioxide in the atmosphere by photosynthesis.
Additionaly carbon dioxide was also decreased by the formation of sedimentary rocks and fossil fuels that contain carbon.