In the last few years, nivolumab has become the standard of care for advanced-stage lung cancer patients. Unfortunately, up to 60% of patients do not respond to this treatment. In our study, we identified variations in gene expression related to primary resistance to immunotherapy. Bronchoscopy biopsies were obtained from advanced non-small cell lung cancer (NSCLC) patients previously characterized as responders or non-responders after nivolumab treatment. Ten tumor biopsies (from three responders and seven non-responders) were analyzed by the differential expression of 760 genes using the NanoString nCounter platform. These genes are known to be involved in the response to anti-PD1/PD-L1 therapy. All the patients were treated with nivolumab. Examining the dysregulated expression of 24 genes made it possible to predict the response to nivolumab treatment. Supervised analysis of the gene expression profile (GEP) revealed that responder patients had significantly higher levels of expression of CXCL11, NT5E, KLRK1, CD3G, GZMA, IDO1, LCK, CXCL9, GNLY, ITGAL, HLA-DRB1, CXCR6, IFNG, CD8A, ITK, B2M, HLA-B, and HLA-A than did non-responder patients. In contrast, PNOC, CD19, TP73, ARG1, FCRL2, and PTGER1 genes had significantly lower expression levels than non-responder patients. These findings were validated as predictive biomarkers in an independent series of 201 patients treated with nivolumab (22 hepatocellular carcinomas, 14 non-squamous cell lung carcinomas, 5 head and neck squamous cell carcinomas, 1 ureter/renal pelvis carcinoma, 120 melanomas, 4 bladder carcinomas, 31 renal cell carcinomas, and 4 squamous cell lung carcinomas). ROC curve analysis showed that the expression levels of ITK, NT5E, ITGAL, and CD8A were the best predictors of response to nivolumab. Further, 13/24 genes showed an adverse impact on overall survival (OS) in an independent, large series of patients with NSCLC (2166 cases). In summary, we found a strong association between the global GEP of advanced NSCLC and the response to nivolumab. The classification of NSCLC patients based on GEP enabled us to identify those patients who genuinely benefited from treatment with immune checkpoint inhibitors (ICIs). We also demonstrated that abnormal expression of most of the markers comprising the genomic signature has an adverse influence on OS, making them significant markers for therapeutic decision-making. Additional prospective studies in larger series of patients are required to confirm the clinical utility of these biomarkers.