Chronic obstructive pulmonary disease (COPD) is now considered among the top three contributors to mortality globally. There is limited understanding surrounding the contribution of magnesium to the progression of COPD. This survey aims to evaluate the connection between dietary magnesium intake and both lung function and COPD prevalence among the US population. The research comprised 4865 participants in the National Health and Nutrition Examination Survey (NHANES) program conducted from 2007 to 2012. To evaluate the association between dietary magnesium intake and lung function as well as COPD, the study conducted multiple regression analyses, stratified analyses, and smoothed curves. In this study, we explored the relationship between higher magnesium intake and higher FEV 1 [β = 0.21 (95% CI 0.12, 0.30)] and FVC [β = 0.25 (95% CI 0.14, 0.36)] after accounting for all potential confounding factors. We demonstrated a relationship between increased magnesium intake and reduced odds of developing COPD [OR = 0.9993 (95% CI 0.9987, 1.0000)]. The results of stratified analyses further indicated that the relationship between magnesium intake and the risk of COPD is more pronounced in the 40-60 age group and males. The study demonstrated positive associations between the intake of dietary magnesium and both FEV 1 and FVC. Additionally, an adverse relationship between magnesium intake and the prevalence of COPD was also observed, suggesting that supplementation with magnesium may be a practical approach to preventing and managing COPD.