Mapping the complex biogeography of microbial communities in situ with high taxonomic and spatial resolution poses a major challenge because of the high density1 and rich diversity2 of species in environmental microbiomes and the limitations of optical imaging technology3-6. Here we introduce high-phylogenetic-resolution microbiome mapping by fluorescence in situ hybridization (HiPR-FISH), a versatile technology that uses binary encoding, spectral imaging and decoding based on machine learning to create micrometre-scale maps of the locations and identities of hundreds of microbial species in complex communities. We show that 10-bit HiPR-FISH can distinguish between 1,023 isolates of Escherichia coli, each fluorescently labelled with a unique binary barcode. HiPR-FISH, in conjunction with custom algorithms for automated probe design and analysis of single-cell images, reveals the disruption of spatial networks in the mouse gut microbiome in response to treatment with antibiotics, and the longitudinal stability of spatial architectures in the human oral plaque microbiome. Combined with super-resolution imaging, HiPR-FISH shows the diverse strategies of ribosome organization that are exhibited by taxa in the human oral microbiome. HiPR-FISH provides a framework for analysing the spatial ecology of environmental microbial communities at single-cell resolution.