Introduction Antimicrobial drugs are known to have effects on the human gut microbiota. We studied the long-term temporal relationship between several antimicrobial drug groups and the composition of the human gut microbiota determined in feces samples. Methods Feces samples were obtained from a community-dwelling cohort of middle-aged and elderly individuals (Rotterdam Study). Bacterial DNA was isolated and sequenced using V3/V4 16 S ribosomal RNA sequencing (Illumina MiSeq). The time between the last prescription of several antimicrobial drug groups and the day of sampling was categorized into 0–12, 12–24, 24–48 and >48 months. The effects of the antimicrobial drug groups on the Shannon alpha-diversity (diversity), the Bray–Curtis beta-diversity (community structure), the Firmicutes/Bacteroidetes (F/B) ratio and individual genera were determined. Results We studied the gut microbiota of 1413 individuals (57.5% female, median age 62.6 years). The alpha-diversity was significantly lower up to 4 years after prescriptions of macrolides and lincosamides. It was also lower in the first year after the use of beta-lactams. The community structure (beta-diversity) of the microbiota was significantly different up to 4 years for macrolides and lincosamides, the first year for beta-lactams and at least the first year for quinolones. For the F/B ratio, drugs with a high anaerobic activity shifted the ratio toward Firmicutes in the first year whereas other antimicrobial drugs shifted the ratio toward Bacteroidetes. Conclusion Use of antimicrobial drugs is associated with a shift in the composition of the gut microbiota.These effects differ in strength and duration, depending on the antimicrobial drug group used. These findings should be considered when prescribing antimicrobial drugs.