Outgassing from volcanism, supplemented by gases produced during the late heavy bombardment of Earth by huge asteroids, produced [Earth's second] atmosphere, consisting largely of nitrogen plus carbon dioxide and inert gases.
However, it doesn't explain any further than that. Where exactly did the nitrogen come from? Was it already gaseous or was it in the form of compounds that broke down releasing N2 gas?
There was some free nitrogen in the secondary atmosphere, and also some ammonia (NH3). Ammonia is present today in the atmospheres of Jupiter, Saturn and other gas giants in the outer solar system. The main constituent of the Earth's primeval atmosphere was carbon dioxide, which also makes up the bulk of the atmospheres of Venus and Mars. The ammonia eventually decomposed into nitrogen and hydrogen.
When we look at the atmospheres of Mars and Venus, we see that they contain only 3 percent nitrogen, while our atmosphere contains 78 percent. The main reason for this is that Mars and Venus still retain most of their primeval CO2, while Earth's has largely disappeared because of biological processes (coal,limestone etc). The atmosphere of Titan also contains a massive percentage of nitrogen because competing gases, apart from methane, have mostly disappeared, frozen out by the intense cold
We also need to consider outgassing from volcanoes. These emissions consist mainly of CO2 and water vapour, but there are small amounts of nitrogen and ammonia, and other gases as well.