The human gastrointestinal tract is divided into sections, allowing digestion and nutrient absorption in the proximal region to be separate from the vast microbial populations in the large intestine, thereby reducing conflict between host and microbes. In the distinct habitats of the gut, environmental filtering and competitive exclusion between microbes are the driving factors shaping microbial diversity, and stochastic factors during colonization history and in situ evolution are likely to introduce intersubject variability. Adaptive strategies of microbes with different niches are genomically encoded: Specialists have smaller genomes than generalists, and microbes with environmental reservoirs have large accessory genomes. A shift toward a Neolithic diet increased loads of simple carbohydrates and selected for their increased breakdown and absorption in the small intestine. Humans who outcompeted microbes for the new substrates obtained more energy from their diets and prospered, an evolutionary process reflected in modern population genetics. The three-way interactions between human genetics, diet, and the microbiota fundamentally shaped modern populations and continue to affect health globally.