Background and Objective: This study aims to find the key immune genes and mechanisms of low bone mineral density (LBMD) in ankylosing spondylitis (AS) patients.Methods: AS and LBMD datasets were downloaded from the GEO database, and differential expression gene analysis was performed to obtain DEGs. Immune-related genes (IRGs) were obtained from ImmPort. Overlapping DEGs and IRGs got I-DEGs. Pearson coefficients were used to calculate DEGs and IRGs correlations in the AS and LBMD datasets. Louvain community discovery was used to cluster the co-expression network to get gene modules. The module most related to the immune module was defined as the key module. Metascape was used for enrichment analysis of key modules. Further, I-DEGs with the same trend in AS and LBMD were considered key I-DEGs. Multiple machine learning methods were used to construct diagnostic models based on key I-DEGs. IID database was used to find the context of I-DEGs, especially in the skeletal system. Gene–biological process and gene-pathway networks were constructed based on key I-DEGs. In addition, immune infiltration was analyzed on the AS dataset using the CIBERSORT algorithm.Results: A total of 19 genes were identified I-DEGs, of which IFNAR1, PIK3CG, PTGER2, TNF, and CCL3 were considered the key I-DEGs. These key I-DEGs had a good relationship with the hub genes of key modules. Multiple machine learning showed that key I-DEGs, as a signature, had an excellent diagnostic performance in both AS and LBMD, and the SVM model had the highest AUC value. Key I-DEGs were closely linked through bridge genes, especially in the skeletal system. Pathway analysis showed that PIK3CG, IFNAR1, CCL3, and TNF participated in NETs formation through pathways such as the MAPK signaling pathway. Immune infiltration analysis showed neutrophils had the most significant differences between case and control groups and a good correlation with key I-DEG.Conclusion: The key I-DEGs, TNF, CCL3, PIK3CG, PTGER2, and IFNAR1, can be utilized as biomarkers to determine the risk of LBMD in AS patients. They may affect neutrophil infiltration and NETs formation to influence the bone remodeling process in AS.