The human intestinal microbiota, comprising trillions of microorganisms, exerts a substantial effect on the host. The microbiota plays essential roles in the function and development of several physiological processes, including those in the brain. A disruption in the microbial composition of the gut has been associated with many metabolic, inflammatory, neurodevelopmental, and neurodegenerative disorders. Nutrition is one of several key factors that shape the microbial composition during infancy and throughout life, thereby affecting brain structure and function. This review examines the effect of the gut microbiota on brain function. The ability of external factors, such as diet, to influence the microbial composition implies a certain vulnerability of the gut microbiota. However, it also offers a potential therapeutic strategy for ameliorating symptoms of mental and physical disorders. Therefore, this review examines the potential effect of nutritional components on gut microbial composition and brain function.