Abstract Background and Aims Diabetes Mellitus (DM) and Chronic Kidney Disease (CKD) are leading causes of morbidity and mortality, presenting challenges in patient management. The aim of this study is to develop a machine learning-based predictive model for mortality in DM and CKD patients, improving early intervention and treatment personalization. Method 3,637 participants with DM and CKD from the National Health and Nutrition Examination Survey (NHANES) from 1999 to 2018 were included. All-cause mortality was ascertained by linkage to National Death Index records through 31 December 2019 in NHANES. The dataset included clinical profiles, demographic details, and laboratory results of patients with DM and CKD. We performed 100 random groupings, dividing the data into a 75% training set and a 25% validation set each time. We then visualized the results of 100 AUC measurements using a boxplot. The objective was to forecast patient survival over 1, 3, 5, and 10-year horizons using a variety of machine learning algorithms. The algorithms tested included Logistic Regression (LR), Decision Tree (DT), Random Forest (RF), K-Nearest Neighbors (KNN), Gaussian Naive Bayes (GNB), Multinomial Naive Bayes (MNB), Bayesian Network Classifier (BNC), AdaBoost (Ada), Gradient Boosting (Gradient), and Extreme Gradient Boosting (XG). The performance of each algorithm was evaluated based on the Area Under the Receiver Operating Characteristic (ROC) Curve (AUC), with the results visualized in boxplot format. Results Upon result shown as the boxplots, it becomes evident that the Random Forest (RF) algorithm consistently exhibits one of the highest AUCs on average across all prediction intervals, suggesting a strong and stable predictive capacity. In the 1-year survival prediction, the RF algorithm demonstrates a highest AUC, implying consistent performance. The 3 and 5-year predictions reveal a slight dip in AUC for most models, including RF, but it still remains one of the top-performing algorithms with fewer outliers than XG and Gradient Boosting. The mean AUC of RF is particularly noteworthy at the 10-year mark, where most algorithms struggle with prediction accuracy, as indicated by lower median AUCs and greater variability. Notably, the RF algorithm identified six major factors for 1-year survival prediction: systolic blood pressure, uric acid, blood urea nitrogen, lactate dehydrogenase, lymphocyte count and total cholesterol, as well as three major factors for 10-year survival prediction: age, lymphocyte and gamma-glutamyl transferase. Conclusion Overall, the study indicates that while machine learning can be a powerful tool for survival prediction in patients with DM and CKD, the choice of algorithm is crucial, with RF standing out for its consistent and reliable performance.