Several dietary ingredients may affect the bacterial community structure and metabolism in the porcine gut and may therefore influence animals" health and performance. This study investigated the effects of cereal source and calcium-phosphorus (CaP) level in the diet on bacterial microbiota and metabolites, nutrient intake, and gut environment in weaned pigs. Pigs (n=8/treatment) were fed wheat-barley- or corn-based diets with an adequate or high CaP level for 14 days. Effects on microbiota in the stomach, ileum, and midcolon were assessed using quantitative PCR. Data showed that Enterobacteriaceae, Campylobacter spp., and Helicobacter spp., which all contain highly immune reactive lipopolysaccharide (LPS), were abundant at all gut sites. Diet effects on bacteria and metabolites were moderate and occurred mainly in the upper gut, whereas no effects on bacteria, fermentation products, and LPS could be observed in the colon. Differences in carbohydrate intake with corn versus wheat-barley diets selectively stimulated Bifidobacterium in the stomach and ileum. There was a growth advantage for a few bacterial groups in the stomach and ileum of pigs fed the high versus adequate CaP level (i.e., gastric Enterobacteriaceae and ileal Enterococcus, Bacteroides-Prevotella-Porphyromonas, and Campylobacter). Interestingly, gastrointestinal pH was not affected by dietary CaP level. The present findings demonstrate the stability of the bacterial community and gut environment toward dietary changes even in young pigs. The results on stimulation of gastric and ileal Bifidobacterium by corn diets may be employed in nutritional strategies to support gut health after weaning.