Previous studies have reported that the significant association between serum calcium and mortality substantially in patients, especially among those with intensive care unit (ICU). And In diabetes mellitus, congestive heart failure (CHF) is a significant comorbidity. We aim to evaluate the association between serum calcium levels and in-hospital mortality among patients with diabetes and congestive heart failure. The participants in this study were extracted from the Medical Information Mart for Intensive Care IV (MIMIC-IV) database. To scrutinize potential associations between serum calcium levels and in-hospital mortality, a comprehensive analysis encompassing multivariate logistic regression, cubic spline function model, threshold effect analysis, and subgroup analysis was performed. This retrospective cohort study encompassed 7063 patients, among whom the in-hospital mortality stood at 12.2%. In the multivariate logistic regression, adjusted odds ratios (ORs) were contrasted with the reference category Q6 (8.8–9.1 mg/dL) for serum calcium levels and in-hospital mortality. The adjusted ORs for Q1 (≤ 7.7 mg/dL), Q2 (7.7–8 mg/dL), and Q7 (≥ 9.1 mg/dL) were 1.69 (95% CI 1.17–2.44, p = 0.005), 1.62 (95% CI 1.11–2.36, p = 0.013), and 1.57 (95% CI 1.1–2.24, p = 0.012) respectively. The dose–response analysis uncovered a U-shaped relationship between serum calcium levels and in-hospital mortality in diabetic patients with heart failure. Subgroup analyses confirmed result stability notwithstanding the influence of diverse factors. Our investigation revealed a U-shaped correlation between serum calcium levels and in-hospital mortality in diabetes patients with congestive heart failure, pinpointing a significant inflection point at 9.05 mg/dL.