• Higher dietary and total fiber intake was significantly positively associated with cognitive function. • Fruit fiber intake was positively associated with Digit Symbol Substitution Test (DSST) and animal fluency test score. • Vegetable fiber intake was positively associated with DSST, CERAD word learning test and the composite cognition score. • No significant interaction effect between gender and fiber intake was found. To investigate the association between dietary fiber intake and cognitive function in the US elderly, a cross-sectional study in the National Health and Nutrition Examination Survey was conducted. Higher dietary and total fiber intake were positively associated with the composite cognition score (P for trend < 0.05). Compared with the lowest quartile of fruit fiber intake, the second quartile was positively related with Digit Symbol Substitution Test (DSST) score (β (95% CI): 1.75 (0.11, 3.38)), and the third quartile was positively related with animal fluency test score (β (95% CI): 0.71 (0.02, 1.40)). Vegetable fiber intake was positively associated with DSST, Consortium to Establish a Registry for Alzheimer’s disease word learning test and the composite cognition score (β (95% CI) for the highest quartile was 2.44 (0.42, 4.47), 1.47 (0.50, 2.44), and 0.15 (0.05, 0.26), respectively). No significant interaction effect between gender and fiber intake was found.