Background Endometriosis (EMs) is a common condition that causes dysmenorrhea, chronic pelvic pain, and infertility, affecting millions of women worldwide. Despite the use of assisted reproductive technology, EMs patients often experience lower embryo implantation rates and recurrent implantation failure (RIF) due to impaired uterine endometrial receptivity. This study aims to identify shared diagnostic genes and underlying mechanisms between EMs and RIF using integrated transcriptomic analysis and machine learning with Gene Expression Omnibus (GEO) datasets.Methods We analyzed GSE11691, GSE7305, GSE111974, and GSE103465 as training datasets for EMs and RIF, and GSE25628 and GSE92324 as validation datasets. Differentially expressed genes (DEGs) and Weighted Gene Co-Expression Network Analysis (WGCNA) identified key genes specific to and shared by EMs and RIF. Machine learning algorithms were used to determine the shared diagnostic gene, whose performance was validated in both training and validation datasets. Single-gene Gene Set Enrichment Analysis (GSEA) revealed shared biological processes in EMs and RIF, while CIBERSORT analysis highlighted similarities and differences in immune infiltration between the two conditions. Finally, endometrial samples from healthy controls, EMs, and RIF patients were collected, and qRT-PCR was performed to validate the diagnostic gene.Results We identified 48 shared key genes between EMs and RIF. The diagnostic gene EHF was selected through machine learning algorithms, and its diagnostic performance was validated in both training and validation datasets. ROC curve analysis demonstrated excellent diagnostic accuracy of EHF for both diseases. Gene Set Enrichment Analysis (GSEA) revealed that both conditions shared biological processes, including dysregulated extracellular matrix remodeling and abnormal immune infiltration. Furthermore, we validated the expression of EHF in endometrial samples from healthy controls, EMs, and RIF patients. Additionally, we characterized the immune microenvironment in EMs and RIF, highlighting changes in immune cell components associated with EHF.Discussion The diagnostic gene EHF identified in this study may serve as a key link between EMs and RIF. The shared pathological processes in both conditions involve alterations in the extracellular matrix and subsequent changes in the immune microenvironment. These findings provide novel insights into potential therapeutic strategies for improving infertility treatment in patients with EMs.