This study focused on the development and validation of a diagnostic model to differentiate between spinal tuberculosis (STB) and pyogenic spondylitis (PS). We analyzed a total of 387 confirmed cases, out of which 241 were diagnosed with STB and 146 were diagnosed with PS. These cases were randomly divided into a training group (n = 271) and a validation group (n = 116). Within the training group, four machine learning (ML) algorithms (least absolute shrinkage and selection operator [LASSO], logistic regression analysis, random forest, and support vector machine recursive feature elimination [SVM-RFE]) were employed to identify distinctive variables. These specific variables were then utilized to construct a diagnostic model. The model’s performance was subsequently assessed using the receiver operating characteristic (ROC) curves and the calibration curves. Finally, internal validation of the model was undertaken in the validation group. Our findings indicate that PS patients had an average platelet-to-neutrophil ratio (PNR) of 277.86, which was significantly higher than the STB patients’ average of 69.88. The average age of PS patients was 54.71 years, older than the 48 years recorded for STB patients. Notably, the neutrophil-to-lymphocyte ratio (NLR) was higher in PS patients at 6.15, compared to the 3.46 NLR in STB patients. Additionally, the platelet volume distribution width (PDW) in PS patients was 0.2, compared to 0.15 in STB patients. Conversely, the mean platelet volume (MPV) was lower in PS patients at an average of 4.41, whereas STB patients averaged 8.31. Hemoglobin (HGB) levels were lower in PS patients at an average of 113.31 compared to STB patients' average of 121.64. Furthermore, the average red blood cell (RBC) count was 4.26 in PS patients, which was less than the 4.58 average observed in STB patients. After evaluation, seven key factors were identified using the four ML algorithms, forming the basis of our diagnostic model. The training and validation groups yielded area under the curve (AUC) values of 0.841 and 0.83, respectively. The calibration curves demonstrated a high alignment between the nomogram-predicted values and the actual measurements. The decision curve indicated optimal model performance with a threshold set between 2% and 88%. In conclusion, our model offers healthcare practitioners a reliable tool to efficiently and precisely differentiate between STB and PS, thereby facilitating swift and accurate diagnoses.