The impact of the tumor immune microenvironment on overall survival in non‐small cell lung cancer (
NSCLC
) has been studied, but there is little information on its relevance for risk of relapse after surgery. Understanding more about the immune microenvironment in previously untreated
NSCLC
could help in identifying high‐risk patients and patients more likely to benefit from neoadjuvant/adjuvant immunotherapy. Here, we examined gene expression in 399 surgically derived
NSCLC
samples and 47 samples from normal lung, using Agilent microarray and
RNA
sequencing. In 335 of the tumor samples, programmed death‐ligand 1 (
PD
‐L1) expression was evaluated by immunohistochemistry. Gene expression was used to estimate content of immune cells and to calculate an immune score. Properties of the immune microenvironment, and its impact on prognosis, were compared in histological subgroups and gene expression subtypes. Tumors with an active immune microenvironment were found for both adenocarcinomas (
AD
) and squamous cell carcinomas (
SCC
). In
AD
, high immune score and high estimates of several immune cell types belonging to the adaptive immune system were associated with better progression‐free survival (
PFS
), while in
SCC
, no association between immune characteristics and
PFS
was found. The immune microenvironment, including
PD
‐L1 expression, and its impact on prognosis showed clear differences in
AD
and
SCC
gene expression subtypes. In conclusion, the
NSCLC
immune microenvironment is predictive of prognosis after surgery. Lung
AD
and
SCC
gene expression subtypes should be investigated as potential prognostic biomarkers in patients treated with immune checkpoint inhibitors.