Nitrifying bacteria living in the soil and others living in nodules on the roots of certain plants combine nitrogen gas from the air with hydrogen to produce ammonia. The ammonia reacts with other substances in the soil to form various nitrates which are the form of nitrogen most readily usable by green plants.
Soil nitrates are also produced by other bacteria that transform the protein compounds of dead plant and animal bodies into nitrates. "What goes around comes around" is an apt cliché for this biological cycle.