Objective: Metformin as a common antidiabetic drug, has recently found to exert its anti-cancer and immunomodulatory effect in numerous preclinical studies. This study aims to clarify the prognostic impact of metformin use in solid cancer patients receiving immune checkpoint inhibitors (ICIs).Methods: A retrospective cohort enrolling 516 solid cancer patients who received ICI-based therapy between 2018 and 2023 at three hospitals was analyzed. The primary endpoints included overall survival (OS) and progression-free survival (PFS). In addition, a bioinformatics analysis based on TCGA and GSE cohort was performed to investigate the prognostic significance of metformin target genes (MTGs) and their correlation with immune infiltration in non-small cell lung cancer (NSCLC) patients.Results: In the entire cohort, a total of 76 patients received metformin before and/or during ICI therapy. The global analysis demonstrated that metformin use was unrelated with the OS (p = 0.064) and PFS (p = 0.059) of ICI-treated cancer patients, which was confirmed in the subgroups of esophagus, hepatobiliary or pancreatic cancer (all p > 0.05). However, metformin use was significantly correlated with better OS (p = 0.012) and PFS (p = 0.005) in ICI-treated lung cancer patients. Metformin use was also identified as an independent favorable prognostic factor for these patients. The bioinformatics analysis identified five favorable prognostic MTGs (RPS6KA5, RORA, SH3BP5, NUPR1, and CD40LG) for NSCLC patients, all of which was downregulated in lung cancer tissues as compared with normal tissues. The expressions of five MTGs not only could effectively stratify the OS of NSCLC patients, but also was correlated with infiltration of immune cells such as CD4+ and CD8+ T cells.Conclusion: Metformin use was significantly correlated with better OS and PFS in ICI-treated lung cancer patients. MTGs has the potential to serve as novel clinical biomarkers or druggable targets for cancer immunotherapy. Considering study limitations, the actual impact of metformin use on ICI therapy needs to be clarified by more clinical trials.