With the increasing prevalence of diabetes mellitus worldwide, type 2 diabetes mellitus (T2D) combined with cognitive impairment and aging has become one of the common and important complications of diabetes mellitus, which seriously affects the quality of life of the patients, and imposes a heavy burden on the patientsâ families and the society. Currently, there are no special measures for the treatment of cognitive impairment and aging in type 2 diabetes mellitus. Therefore, the search for potential biological markers of type 2 diabetes mellitus combined with cognitive impairment and aging is of great significance for future precisive treatment. We downloaded three gene expression datasets from the GEO database: GSE161355 (related to T2D with cognitive impairment and aging), GSE122063, and GSE5281 (related to Alzheimerâs disease). Differentially expressed genes (DEGs) were identified, followed by gene set enrichment analysis (GSEA). A protein-protein interaction (PPI) network was constructed using the STRING database, and the top 15 hub genes were identified using the CytoHubba plugin in Cytoscape. Core genes were ultimately determined using three machine learning methods: LASSO regression, Support Vector Machine Recursive Feature Elimination (SVM-RFE), and Linear Discriminant Analysis (LDA). The diagnostic performance of these genes was assessed using ROC curve analysis and validated in an independent dataset (GSE5281). Regulatory genes related to ferroptosis were screened from the FerrDb database, and their biological functions were further explored through GO and KEGG enrichment analyses. Finally, the CIBERSORT algorithm was used to analyze immune cell infiltration, and the correlation between core genes and immune cell infiltration levels was calculated, leading to the construction of an mRNA-miRNA regulatory network. In the GSE161355 and GSE122063 datasets, 217 common DEGs were identified. GSEA analysis revealed their enrichment in the PI3K-PLC-TRK signaling pathway, TP53 regulation of metabolic genes pathway, Notch signaling pathway, among others. PPI network analysis identified 15 candidate core genes, and further selection using LASSO, LDA, and SVM-RFE machine learning algorithms resulted in 6 core genes: BCL6, TP53, HSP90AA1, CRYAB, IL1B, and DNAJB1. ROC curve analysis indicated that these genes had good diagnostic performance in the GSE161355 dataset, with TP53 and IL1B achieving an AUC of 0.9, indicating the highest predictive accuracy. BCL6, HSP90AA1, CRYAB, and DNAJB1 also had AUCs greater than 0.8, demonstrating moderate predictive accuracy. Validation in the independent dataset GSE5281 showed that these core genes also had good diagnostic performance in Alzheimerâs disease samples (AUC > 0.6). Ferroptosis-related analysis revealed that IL1B and TP53 play significant roles in apoptosis and immune response. Immune cell infiltration analysis showed that IL1B is significantly positively correlated with infiltration levels of monocytes and NK cells, while TP53 is significantly negatively correlated with infiltration levels of follicular helper T cells. The construction of the miRNA-mRNA regulatory network suggested that miR-150a-5p might play a key role in the regulation of T2D-associated cognitive impairment and aging by TP53. This study, by integrating bioinformatics and machine learning methods, identified BCL6, TP53, HSP90AA1, CRYAB, IL1B, and DNAJB1 as potential diagnostic biomarkers for T2D with cognitive impairment and aging, with a particular emphasis on the significance of TP53 and IL1B in immune cell infiltration. These findings not only enhance our understanding of the molecular mechanisms linking type 2 diabetes to cognitive impairment and aging, providing new targets for early diagnosis and treatment, but also offer new directions and targets for basic research.