Background: Patients with well-differentiated thyroid carcinoma can achieve long-term survival after reasonable treatments, but there is no standard treatment mode for poorly or undifferentiated thyroid carcinoma and its prognosis is very poor. Immune cells, especially tumor-associated macrophages, account for a large proportion of the tumor microenvironment of anaplastic thyroid carcinomas (ATCs). However, whether immune-related genes can mediate the dedifferentiation of thyroid cells is unclear.Methods: We initially compared the differences of thyroid differentiation score, infitration of immune cells and enriched pathways between ATCs and papillary thyroid carcionma (PTCs) or normal thyroid tissues in Gene Expression Omnibus database. Then, The Cancer Genome Atlas database was used to screen out the prognosis associated IRGs. A risk score was constructed and we next investigated its predictive value for differentiation by applying receiver operating characteristic (ROC) curves and correlation analyses. Kaplan-Meier curves were used to evaluated its prognostic value. We further explored the associations of the risk score with important immune checkpoint molecules, infiltrating immune cells and response to immunotherapy.Results: Compared with PTCs or normal thyroid tissues, ATCs exhibited lower thyroid differentiation scores, higher infiltration of most immune cells and higher activation of inflammatory response. The risk score composed of MMP9 and SDC2 was significantly increased in ATCs and low differentiated PTCs. Moreover, it showed favorable predictive value for differentiation and survival. Higher risk score displayed dedifferentiation status and a worse prognosis. Additionly, the risk score was positively correlated with immune checkpoint molecules PDL1, CTLA4, IDO1, HAVCR2 and infiltration of multiple immune cells. Importantly, we found that samples with higher risk score tend to have a better response to immune checkpoint agents than lower ones.Conclusion: Our findings indicate that the risk score may not only contribute to the judgement of differentiation and prognosis of thyroid cancer, but also help to the prediction of immune cell infiltration and immune checkpoint inhibitor response.