First the atmosphere consisted of hyrogen & helium. These were given off as the planet formed but as both gases are light they drifted off into space.
Our atmosphere was originally formed from the gases given out by volcanoes - carbon dioxide, water vapour, ammonia & methane.
The Earth cooled & the water vapour condensed to form oceans.
Over time the carbon dioxide dissolved in the oceans & this led to the formation of carbonate rocks.
Plants evolved & produced oxygen via photosynethesis.
Ammonia reacted with oxygen to produce nitrogen.
Methane also reacted with oxygen to produce carbon dioxide & water.