BackgroundObesity is a well-known risk factor for gallstone disease, but the underlying mechanisms remain unclear. Recent studies suggest that inflammation may mediate the relationship between obesity and gallstones. This study, based on the 2017-2020 NHANES dataset, aims to explore this association and assess the mediating role of inflammatory markers.MethodsWe analyzed data from 7,978 adults aged 20 years and older. Gallstones were self-reported, and obesity was defined as a BMI >= 30. Inflammatory markers included white blood cell count (WBC), neutrophil count (NEU), neutrophil-to-lymphocyte ratio (NLR), platelet-to-lymphocyte ratio (PLR), C-reactive protein (CRP), and the systemic immune inflammation index (SII). Multivariable logistic regression and causal mediation analysis were used to examine direct associations and mediation effects, adjusting for potential confounders. Subgroup analyses by age and sex were also performed.ResultsObesity was significantly associated with an increased incidence of gallstones (OR = 2.29; 95% CI, 1.98-2.65). After adjusting for confounders, including age, sex, smoking, and alcohol consumption, the relationship remained significant (OR = 1.86; 95% CI, 1.57-2.22). Inflammatory markers, such as WBC (OR = 1.61; 95% CI, 1.22-2.11), NEU (OR = 1.46; 95% CI, 1.17-1.81), and CRP (OR = 1.18; 95% CI, 1.10-1.28), were also significantly associated with gallstones. Causal mediation analysis indicated that inflammatory markers, particularly WBC, NEU, and CRP, mediated the relationship between obesity and gallstones. Subgroup analysis showed the association was consistent across age groups, but mediating effects varied by age and sex. In the 41-60 years group, WBC and NEU had significant mediating effects, while in those over 60, PLR showed a negative association. In females, the mediating effect of inflammatory markers was not significant after adjustments.ConclusionsThis study demonstrates a significant association between obesity and gallstones, with inflammatory markers playing a partial mediating role in this relationship. Modulating levels of inflammation may help reduce the risk of gallstone formation associated with obesity.