Anal fistula is a common proctological disease, but the thorough mechanisms of the anal fistula formation are still unclear. An increasing number of studies have revealed the crucial role of gut microbiota in intestinal diseases. We used 16S rRNA gene sequencing to analyze the intestinal microbiome in order to determine whether there are differences in the microbiome between anal fistula patients and healthy individuals. The microbiome samples were extracted by repeatedly wiping the rectal wall with intestinal swab. Before this operation, the whole intestine of all participants was irrigated and the score of the Boston bowel preparation scale reached 9. The biodiversity of gut microbiome of rectum revealed significant difference between anal fistula patients and healthy individuals. 36 discriminative taxa were identified by LEfSe analysis between two groups. At the phylum level,Synergisteteswas enriched in anal fistula patients, whileProteobacteriawas higher in healthy individuals. We also found that at the genus level,Blautia,Faecalibacterium,Ruminococcus,Coprococcus,Bacteroides,Clostridium,MegamonasandAnaerotruncuswere highly enriched in anal fistula patients, while the microbiome of healthy individuals was enriched withPeptoniphilusandCorynebacterium. Spearman correlations showed the extensive and close association among genera and species. Finally, a diagnostic prediction model was constructed by random forest classifier, and the area under curve (AUC) reached 0.990. This study gave an important hint for analyzing gut microbiome of rectum in anal fistula patient.Keypoints.We use the 16S rRNA gene sequencing to test the microbiome samples extracted from the intestinal swab. This is the first study to explore the gut microbiome of rectum using this workflow. We also found the distinct gut microbiome of rectum differences between anal fistula patients and healthy individuals.Supplementary InformationThe online version contains supplementary material available at 10.1186/s13568-023-01560-9.