Inside a red giant star, the star smashes lighter atoms together. Smashing atoms gets the star energy to burn, and also leaves extra heavier atoms. Nitrogen is one of these heavier atoms, left over when a star smashes together carbon atoms. Nitrogen is not very heavy, though, and a lot of stars make a lot of nitrogen. When a red giant star explodes into a supernova, the nitrogen inside it goes shooting off into space. It becomes part of a nebula, or cloud of space dust. All of the nitrogen in the universe comes from inside stars.
Most of the nitrogen in the universe stays in these nebulae. Nitrogen atoms have five electrons in their outer ring, but they have room for eight electrons there. Often they join up with another nitrogen atom, each sharing electrons to fill up the rings. That makes molecules of two nitrogen atoms. Because these nitrogen molecules are very stable, they don’t break apart and join up with other kinds of atoms very much. It takes a lot of energy to break up a nitrogen molecule. But some of the nitrogen in space did become part of larger hydrocarbon molecules called amino acids.
When the Earth formed, about four and a half billion years ago, some nitrogen fell into the Earth’s gravity. Nitrogen became the main ingredient in Earth’s air – more than three-quarters of Earth’s air is made of nitrogen molecules.
When life first evolved on Earth, about three and a half billion years ago, the cells used nitrogen to make protein molecules. Protein molecules are part of what cells are made of, and they also make RNA and DNA, the genetic material that allows cells to reproduce. When the bacteria that used this nitrogen died, the nitrogen decayed out of their bodies. Soon more complicated plants evolved that could use this nitrogen too. Plants use nitrogen just like bacteria do, to make amino acids and proteins. Animals, including people, need nitrogen for the same reasons. We get our nitrogen by eating plants like carrots or lettuce, or by eating other animals, like pigs, that ate plants.