Genomic technologies have significantly advanced our understanding of the composition and diversity of host-associated microbial populations. However, their spatial organization and functional interactions relative to the host have been more challenging to study. Here we present a pipeline for the assessment of intestinal microbiota localization within immunofluorescence images of fixed gut cross-sections that includes a flexible software package, BacSpace, for high-throughput quantification of microbial organization. Applying this pipeline to gnotobiotic and human microbiota-colonized mice, we demonstrate that elimination of microbiota-accessible carbohydrates (MACs) from the diet results in thinner mucus in the distal colon, increased proximity of microbes to the epithelium, and heightened expression of the inflammatory marker REG3β. Measurements of microbe-microbe proximity reveal that a MAC-deficient diet alters monophyletic spatial clustering. Furthermore, we quantify the invasion of Helicobacter pylori into the glands of the mouse stomach relative to host mitotic progenitor cells, illustrating the generalizability of this approach.