How did the Earth's atmosphere get to be so rich in nitrogen and not carbon dioxide?

I don't think this is really known with any certainty, but the most likely explanation I have heard is that the original atmosphere was probably rich in nitrogen compounds such as ammonia (NH3) gas, which is a very common gas found in the Giant Planets, in comet ices and gases, and in interstellar clouds. The ancient Earth atmosphere bust also have been rich in these nitrogen-rich compounds, and through a process of photochemical and possibly biogenic activity, ammonia gases were converted into nitrogen gas and other byproducts. As for Venus and Mars which have atmospheres rich in carbon dioxide, we also know that volcanic activity produces lots of carbon dioxide, which on Earth gets locked up into carbonate rocks via the ocean as a catalyst. On Mars, the ammonia gas was probably lost by evaporation because of the low surface gravity of Mars. On Venus, methane gas was photodissociated into hydrogen and nitrogen. The hydrogen escaped as it also does from the Earth, and the nitrogen gas probably did so as well. Meanwhile, with no bodies of water, Venus could not get rid of the carbon dioxide gas it was producing and that's all that now exists in its atmosphere.