Chronic kidney disease (CKD) is a major complication of diabetes mellitus (DM). Inflammation is an essential component in the process of CKD progression in patients with DM. Diet is a significant determinant of systemic inflammation levels. However, the association between the dietary inflammatory index (DII) and CKD in individuals with DM remains largely unknown; therefore, the aim of this study was to explore whether the DII is linked to the prevalence of CKD in patients with DM. The research method was as follows: first, data from the National Health and Nutrition Examination Survey (NHANES) between 1999 and 2018 were obtained. There were 7,974 participants in our study. These individuals were then classified into three groups according to DII tertiles (T1-T3), with each group consisting of 2,658 participants. Logistic regression analysis was employed to examine whether there was a connection between the DII and CKD. We observed a significant association between the DII and the prevalence of CKD in individuals with DM. After full adjustment for age, sex, ethnicity, smoking, drinking, body mass index (BMI), triglyceride (TG), total cholesterol (TC), metabolic equivalents (METs), energy intake, hypoglycemic medications, hypertension, and cardiovascular disease (CVD), the group with a higher DII had a greater frequency of CKD (T2 group: OR: 1.40; 95% CI: 1.10–1.76; p = 0.006; T3 group: OR: 1.67; 95% CI: 1.29–2.17; p < 0.001). The implementation of an anti-inflammatory diet could serve as an intervention strategy for patients with DM to prevent the onset of CKD.