Biological nitrogen fixation is an important source of fixed nitrogen for the biosphere. Microorganisms catalyse biological nitrogen fixation with the enzyme nitrogenase, which has been highly conserved through evolution. Cloning and sequencing of one of the nitrogenase structural genes, nifH, has provided a large, rapidly expanding database of sequences from diverse terrestrial and aquatic environments. Comparison of nifH phylogenies to ribosomal RNA phylogenies from cultivated microorganisms shows little conclusive evidence of lateral gene transfer. Sequence diversity far outstrips representation by cultivated representatives. The phylogeny of nitrogenase includes branches that represent phylotypic groupings based on ribosomal RNA phylogeny, but also includes paralogous clades including the alternative, non-molybdenum, non-vanadium containing nitrogenases. Only a few alternative or archaeal nitrogenase sequences have as yet been obtained from the environment. Extensive analysis of the distribution of nifH phylotypes among habitats indicates that there are characteristic patterns of nitrogen fixing microorganisms in termite guts, sediment and soil environments, estuaries and salt marshes, and oligotrophic oceans. The distribution of nitrogen-fixing microorganisms, although not entirely dictated by the nitrogen availability in the environment, is non-random and can be predicted on the basis of habitat characteristics. The ability to assay for gene expression and investigate genome arrangements provides the promise of new tools for interrogating natural populations of diazotrophs. The broad analysis of nitrogenase genes provides a basis for developing molecular assays and bioinformatics approaches for the study of nitrogen fixation in the environment.