It is believed that the Earth was formed around 4.5 billion years ago, and the atmosphere then was probably gases (mainly CO2 & small proportions of methane, ammonia and water vapour.) given out by volcanoes.
2 billion years ago:
The Earth's surface was molten when it was first formed, however as it cooled, surface rocks formed. Nitrogen was probably also released, which built up in the atmosphere as it is unreactive.
1 billion years ago
As the earth cooled, the water vapour condensed to form oceans. The main gas in the atmosphere was still CO2, and it was at this point that simple plants began to evolve.
The first plant produced oxygen. This lead to many life forms dying out as they were adapted to live off CO2. 6H2O + 6CO2 → C6H12O6 + 6O2
The excess oxygen produced by plants reacted in the presence of UV light to form the ozone layer. This prevented damage by UV light allowing more complicated life forms to evolve.
The atmosphere is now approximately 1/5 oxygen and 4/5 nitrogen. CO2 is absorbed by plants as well as shellfish, and dissolved in the oceans. However it is given out by the burning of fossil fuels. Ammonia in the air has reacted with oxygen to form nitrogen. More nitrogen was formed by bacteria in the soil.