Objective: Ankylosing spondylitis (AS) is a chronic inflammatory disease characterized by the inflammation of the spine and sacroiliac joints. Understanding the underlying immune cells and key genes associated with AS is crucial for unraveling its pathogenesis. In this study, we employed weighted gene co-expression network analysis (WGCNA) to identify immune cells and key genes involved in AS. The GSE11886 dataset, obtained from the GEO database, was utilized for the analysis of differentially expressed genes (DEGs). Subsequently, the WGCNA package was applied to screen for key modules and genes that correlated with clinical characteristics of AS. The intersection of DEGs obtained from the analysis and genes within the blue module led to the identification of key genes, which were further subjected to correlation analysis. Our findings revealed a total of 279 DEGs, including 123 up-regulated and 156 down-regulated genes, as determined by a volcano map. Additionally, WGCNA analysis unveiled a key module strongly associated with AS. Within this module, we identified 22 key genes, namely CLIC3, LY75, TNFAIP3, TNFAIP6, STAT1, GBP1, TNFSF13B, CD69, IFITM1, WLS, CNRIP1, LY86, ICAM4, NMRK2, DNASE2B, AMDHD1, TUBB2A, DEXI, TPD52L1, ASRGL1, CECR6, and FAM213B. The discovery of these modules and key genes provides a theoretical foundation for further exploration of the mechanisms underlying the development and progression of AS.