4.5 billion years ago, the earth had an atmosphere formed from vapor and gasses that were released from degassing.
One billion years ago, early aquatic organisms called blue-green algae began using energy from the Sun to split molecules of H2O and CO2 and recombine them into organic compounds and molecular oxygen.
Why is there so much nitrogen?
High in the atmosphere, some oxygen molecules absorbed energy from the Sun's (UV) rays and split to form single oxygen atoms.These atoms combining with remaining oxygen to form ozone molecules, which arevery effective at absorbing UV rays. This was the creation of the Ozone Layer
Now, our earth is covered with 79% nitrogen, 20% oxygen and 1% trace element.