Despite the achievements of modern medicine, tuberculosis remains one of the leading causes of mortality globally. The difficulties in differential diagnosis have particular relevance in the case of suspicion of tuberculosis with other granulomatous diseases. The most similar clinical and radiologic changes are sarcoidosis. The aim of this study is to apply mathematical modeling to determine diagnostically significant immunological parameters and an algorithm for the differential diagnosis of tuberculosis and sarcoidosis. Materials and methods: The serum samples of patients with sarcoidosis (SD) (n = 29), patients with pulmonary tuberculosis (TB) (n = 32) and the control group (n = 31) (healthy subjects) collected from 2017 to 2022 (the average age 43.4 ± 5.3 years) were examined. Circulating 'polarized' T-helper cell subsets were analyzed by multicolor flow cytometry. A symbolic regression method was used to find general mathematical relations between cell concentrations and diagnosis. The parameters of the selected model were finally fitted through multi-objective optimization applied to two conflicting indices: sensitivity to sarcoidosis and sensitivity to tuberculosis. Results: The difference in Bm2 and CD5-CD27- concentrations was found to be more significant for the differential diagnosis of sarcoidosis and tuberculosis than any individual concentrations: the combined feature Bm2 - [CD5-CD27-] differentiates sarcoidosis and tuberculosis with p < 0.00001 and AUC = 0.823. An algorithm for differential diagnosis was developed. It is based on the linear model with two variables: the first variable is the difference Bm2 - [CD5-CD27-] mentioned above, and the second is the naïve-Tregs concentration. The algorithm uses the model twice and returns "dubious" in 26.7% of cases for patients with sarcoidosis and in 16.1% of cases for patients with tuberculosis. For the remaining patients with one of these two diagnoses, its sensitivity to sarcoidosis is 90.5%, and its sensitivity to tuberculosis is 88.5%. Conclusions: A simple algorithm was developed that can distinguish, by certain immunological features, the cases in which sarcoidosis is likely to be present instead of tuberculosis. Such cases may be further investigated to rule out tuberculosis conclusively. The mathematical model underlying the algorithm is based on the analysis of "naive" T-regulatory cells and "naive" B-cells. This may be a promising approach for differential diagnosis between pulmonary sarcoidosis and pulmonary tuberculosis. The findings may be useful in the absence of clear differential diagnostic criteria between pulmonary tuberculosis and sarcoidosis.