Findings from gut microbiome studies are strongly influenced by both experimental and analytical factors that can unintentionally bias their interpretation. Environment is also critical. Both co-housing and maternal effects are expected to affect microbiomes and have the potential to confound other manipulated factors, such as genetics. We therefore analysed microbiome data from a mouse experiment using littermate controls and tested differences among genotypes (wildtype versus colitis prone-mdr1a-/-), gut niches (stool versus mucus), host ages (6 versus 18 weeks), social groups (co-housed siblings of different genotypes) and maternal influence. We constructed a 16S phylogenetic tree from bacterial communities, fitting random forest models using all 428,234 clades identified. Models discriminated all criteria except host genotype, where no community differences were found. Host social groups differed in abundant, low-level, taxa whereas intermediate phylogenetic and abundance scales distinguished ages and niches. Thus, a carefully controlled experiment treating evolutionary clades of microbes equivalently without reference to taxonomy, clearly identifies whether and how gut microbial communities are distinct across ecologically important factors (niche and host age) and other experimental factors, notably cage effects and maternal influence. These findings highlight the importance of considering such environmental factors in future microbiome studies.