Recurrent pregnancy loss (RPL) is a complex reproductive disorder. The incompletely understood pathophysiology of RPL makes early detection and exact treatment difficult. The purpose of this work was to discover optimally characterized genes (OFGs) of RPL and to investigate immune cell infiltration in RPL. It will aid in better understanding the etiology of RPL and in the early detection of RPL. The RPL-related datasets were obtained from the Gene Expression Omnibus (GEO), namely GSE165004 and GSE26787. We performed functional enrichment analysis on the screened differentially expressed genes (DEGs). Three machine learning techniques are used to generate the OFGs. A CIBERSORT analysis was conducted to examine the immune infiltration in RPL patients compared with normal controls and to investigate the correlation between OFGs and immune cells. Between the RPL and control groups, 42 DEGs were discovered. These DEGs were found to be involved in cell signal transduction, cytokine receptor interactions, and immunological response, according to the functional enrichment analysis. By integrating OFGs from the LASSO, SVM-REF, and RF algorithms (AUC > 0.880), we screened for three down-regulated genes: ZNF90, TPT1P8, FGF2, and an up-regulated FAM166B. Immune infiltration study revealed that RPL samples had more monocytes (P< 0.001) and fewer T cells (P= 0.005) than controls, which may contribute to RPL pathogenesis. Additionally, all OFGs linked with various invading immune cells to varying degrees. In conclusion, ZNF90, TPT1P8, FGF2, and FAM166B are potential RPL biomarkers, offering new avenues for research into the molecular mechanisms of RPL immune modulation and early detection.