The diverse collection of microorganisms that inhabit the gastrointestinal tract, collectively called the gut microbiota, profoundly influences many aspects of host physiology, including nutrient metabolism, resistance to infection and immune system development. Studies investigating the gut-brain axis demonstrate a critical role for the gut microbiota in orchestrating brain development and behavior, and the immune system is emerging as an important regulator of these interactions. Intestinal microbes modulate the maturation and function of tissue-resident immune cells in the CNS. Microbes also influence the activation of peripheral immune cells, which regulate responses to neuroinflammation, brain injury, autoimmunity and neurogenesis. Accordingly, both the gut microbiota and immune system are implicated in the etiopathogenesis or manifestation of neurodevelopmental, psychiatric and neurodegenerative diseases, such as autism spectrum disorder, depression and Alzheimer's disease. In this review, we discuss the role of CNS-resident and peripheral immune pathways in microbiota-gut-brain communication during health and neurological disease.