The gut-brain axis serves as a bidirectional signaling avenue connecting dietary habits, gut microbiota, and cognitive functions. Fermented foods contain valuable microorganisms and bioactive metabolites, which are increasingly considered to be able to act as precursors for brain modulation. The present study was aimed at exploring the association between consumption of fermented food, composition of gut microbiota, and cognitive performance among undergraduate students. Method: Cross-sectional analytical study on 150 university students (ages of 18-25 years). Dietary consumption of fermented foods was assessed by a validated food frequency questionnaire, while cognitive performance was assessed using the Digit Span Test and Stroop Test. 16S rRNA gene sequencing was performed to analyze gut microbiota diversity. Higher intake of fermented foods was significantly related to greater microbial diversity (p < 0.001) and better cognitive performance, specifically working memory and executive function (p < 0.001). Beneficial bacterial genera (Lactobacillus and Bifidobacterium) showed positive correlations with cognitive scores. These findings indicate that these cognitive benefits of fermented food may partly arise from the modulation of gut microbiota. Causality needs to be confirmed by more longitudinal and interventional studies.