Studies on overall immune infiltration and pyroptosis in patients with multiple sclerosis (MS) are limited. This study explored immune cell infiltration and pyroptosis in MS using bioinformatics and experimental validation. The GSE131282 and GSE135511 microarray datasets including brain autopsy tissues from controls and MS patients were downloaded for bioinformatic analysis. The gene expression-based deconvolution method, CIBERSORT, was used to determine immune infiltration. Differentially expressed genes (DEGs) and functional enrichments were analyzed. We then extracted pyroptosis-related genes (PRGs) from the DEGs by using machine learning strategies. Their diagnostic ability for MS was evaluated in both the training set (GSE131282 dataset) and validation set (GSE135511 dataset). In addition, messenger RNA (mRNA) expression of PRGs was validated using quantitative real-time polymerase chain reaction (qRT-PCR) in cortical tissue from an experimental autoimmune encephalomyelitis (EAE) model of MS. Moreover, the functional enrichment pathways of each hub PRG were estimated. Finally, co-expressed competitive endogenous RNA (ceRNA) networks of PRGs in MS were constructed. Among the infiltrating cells, naive CD4+ T cells (P=0.006), resting NK cells (P=0.002), activated mast cells (P=0.022), and neutrophils (P=0.002) were significantly higher in patients with MS than in controls. The DEGs of MS were screened. Analysis of enrichment pathways showed that the pathways of transcriptional regulatory mechanisms and ion channels associating with pyroptosis. Four PRGs genes CASP4, PLCG1, CASP9 and NLRC4 were identified. They were validated in both the GSE135511 dataset and the EAE model by using qRT-PCR. CASP4 and NLRC4 were ultimately identified as stable hub PRGs for MS. Single-gene Gene Set Enrichment Analysis showed that they mainly participated in biosynthesis, metabolism, and organism resistance. ceRNA networks containing CASP4 and NLRC4 were constructed. MS was associated with immune infiltration. CASP4 and NLRC4 were key biomarkers of pyroptosis in MS.