Midlife obesity is a significant risk factor for Alzheimer's disease, but the effects of obesity on cognitive function, either detrimental or beneficial, are controversial among older individuals. This study aims to assess this associations of body mass index (BMI) or waist circumference (WC) with cognitive function among United States older individuals. A cross-sectional research study was conducted utilizing data from the 2011 to 2014 National Health and Nutrition Examination Survey (NHANES). Initially, the study compared differences in cognitive function among the normal weight, overweight, and obese groups. Subsequently, we examined the relationships between BMI or WC and cognitive function using multivariate linear regression. Finally, structural equation models were constructed to assess the relationships among body shape, lifestyle, and cognitive function pathways. The study included 2254 individuals. Obese subjects had lower scores in the Consortium to Establish a Registry for Alzheimer's Disease (CERAD) word list learning tasks (CERAD-WL) (χ2=7.804, p=.020) and digit symbol substitution test (χ2=8.869, p=.012). The regression analysis showed that WC was negatively connected with the CERAD-WL score after adjusting for confounding factors (β=-.029, p=.045). Moreover, WC had a mediating effect on the path from lifestyle to cognition (CERAD-WL). However, there was no difference in the CERAD delayed recall score and the animal fluency test between the obese and the other groups. Obese older adults exhibited impaired cognitive abilities in terms of learning and working memory performance. The impact of lifestyle on cognition was mediated by obesity-related anthropometric indices. Sleep, physical activity, and diet influenced the degree of obesity, which subsequently determined cognitive function. Prioritizing weight management in elderly people is crucial for safeguarding cognitive function.