Nitrogen fixation how nitrogen in the air (N2) is changed (converted) into ammonia () or other nitrogenous compounds in the soil.

Nitrogen fixation is essential to life because nitrogen compounds are needed for making all nitrogen-containing organic compounds, such as amino acids, proteins, and nucleic acids.

Atmospheric nitrogen is a relatively unreactive molecule. It is useless to all except a few bacteria and archaea. Biological nitrogen fixation converts  into ammonia, which is used (metabolized) by most organisms.

Nitrogen is fixed in biological and non-biological ways:

Biological

Microorganisms that fix nitrogen (diazotrophs)
 Cyanobacteria, e.g. the highly significant Trichodesmium
 Green sulfur bacteria
 Azotobacteraceae
 Rhizobia
 Frankia Gram-positive soil bacteria cause nitrogen-fixing nodules in actinorhizal plants.

Cyanobacteria are in most environments on Earth. They play key roles in the carbon and nitrogen cycle of the biosphere. Cyanobacteria use many sources of combined nitrogen, like nitrate, nitrite, ammonium, urea, or some amino acids. 

Several cyanobacteria are also diazotrophs which can fix nitrogen from the air. This is an ability which may have been present in their last common ancestor in the Archaean. 
Cyanobacteria in coral reefs can fix twice the amount of nitrogen than on land—around 1.8 kg of nitrogen is fixed per hectare per day. The colonial marine cyanobacterium Trichodesmium may fix nitrogen on such a scale that it accounts for almost half of the nitrogen-fixation in marine systems on a global scale.

Root nodule symbioses

Legume family
Plants that contribute to nitrogen fixation include the legume family – Fabaceae – with taxa such as kudzu, clovers, soybeans, alfalfa, lupines, peanuts, and rooibos. They have symbiotic bacteria called Rhizobia in nodules in their root systems, producing nitrogen compounds that help the plant to grow and compete with other plants. When the plant dies, the fixed 
nitrogen is released, making it available to other plants and this helps to fertilize the soil. Most legumes have this association, but a few genera (e.g., Styphnolobium) do not. In traditional farming practice, fields are rotated through various types of crops, which usually includes one consisting mainly or entirely of clover or buckwheat (non-legume family Polygonaceae), which are often referred to as "green manure".

Non-leguminous

Although most plants able to form nitrogen-fixing root nodules are in the legume family Fabaceae, there are a few exceptions:

 Parasponia, a tropical genus in the Cannabaceae also able to interact with rhizobia and form nitrogen-fixing nodules

 Actinorhizal plants such as alder and bayberry, can also form nitrogen-fixing nodules, thanks to a symbiotic association with Frankia bacteria. These plants belong to 25 genera in eight plant families. In these families, not all can fix nitrogen. For example, of 122 genera in the Rosaceae, only 4 genera are capable of fixing nitrogen. 

All these families belong to the orders Cucurbitales, Fagales, and Rosales, which together with the Fabales form a clade. In this clade, Fabales were the first lineage to branch off; thus, the ability to fix nitrogen was lost in most descendants of the original nitrogen-fixing plant. 

Biological nitrogen fixation was discovered by Hermann Hellnegel (18311895) and Martinus Beijerinck (18511931).

Non-biological 
 Lightning. Nitric oxide (NO) from nitrogen gas and oxygen gas due to lightning, is important for the chemistry of the air, but too small to be important for life. 
 Through the Haber process.  Nitrogen gas is combined with hydrogen gas into ammonia for fertilizer and explosives.
 Burning.

References 

Ecology
Biochemistry