Some cyanobacteria can fix atmospheric nitrogen in anaerobic conditions by means of specialized cells called heterocysts. Heterocysts may also form under the appropriate environmental conditions (anoxic) when fixed nitrogen is scarce. Heterocyst-forming species are specialized for nitrogen fixation and are able to fix nitrogen gas into ammonia (), nitrites () or nitrates (), which can be absorbed by plants and converted to protein and nucleic acids (atmospheric nitrogen is not bioavailable to plants, except for those having endosymbiotic nitrogen-fixing bacteria, especially the family Fabaceae, among 
others).
Free-living cyanobacteria are present in the water of rice paddies, and cyanobacteria can be found growing as epiphytes on the surfaces of the green alga, Chara, where they may fix nitrogen. Cyanobacteria such as Anabaena (a symbiont of the aquatic fern Azolla) can provide rice plantations with biofertilizer.