Ampicillin has been shown to improve glucose tolerance in mice. We hypothesized that this effect is present only if treatment is initiated prior to weaning and that it disappears when treatment is terminated. High-fat fed C57BL/6NTac mice were divided into groups that received Ampicillin at different ages or not at all. We found that both diet and Ampicillin significantly changed the gut microbiota composition in the animals. Furthermore, there was a significant improvement in glucose tolerance in Ampicillin-treated, five-week-old mice compared to nontreated mice in the control group. At study termination, expressions of mRNA coding for tumor necrosis factor, serum amyloid A, and lactase were upregulated, while the expression of tumor necrosis factor (ligand) superfamily member 15 was downregulated in the ileum of Ampicillin-treated mice. Higher dendritic cell percentages were found systemically in high-fat diet mice, and a lower tolerogenic dendritic cell percentage was found both in relation to high-fat diet and late Ampicillin treatment. The results support our hypothesis that a "window" exists early in life in which an alteration of the gut microbiota affects glucose tolerance as well as development of gut immunity and that this window may disappear after weaning.