Objective To construct the differential diagnosis model of viral pneumonia and bacterial pneumonia based on lung ultrasonography (LUS) characteristics. Methods A total of 248 patients with pneumonia who completed LUS in our hospital from January 2021 to March 2024 were retrospectively included, and were divided into a viral group (140 cases) and a bacterial group (108 cases) according to the final etiological diagnosis. Predictors in differential diagnosis between viral pneumonia and bacterial pneumonia were analyzed by univariate and multivariate methods. The differential diagnosis model of viral pneumonia and bacterial pneumonia and the prediction efficiency were evaluated. Results Univariate and multivariate logistic analysis showed that the presence or absence of lung consolidation, pleural effusion, B-line range of both lungs and pulmonary ultrasound score were independent predictors of the differential diagnosis of viral pneumonia and bacterial pneumonia (P<0.05). Using the logistic regression model of lung consolidation, pleural effusion, bilateral B-line range, and pulmonary ultrasound score, including the P-values of three variables (lung consolidation, pleural effusion, and bilateral B-line range), and the P-values of four variables (lung consolidation, pleural effusion, bilateral B-line range, and pulmonary ultrasound score), the receiver operating characteristic curve was used to predict the diagnosis of patient. The areas under the curve were 0.863, 0.612, 0.669, 0.684, 0.904, and 0.920, respectively. Conclusion Lung consolidation, pleural effusion, B-line range of both lungs and pulmonary ultrasound score detected by LUS have good diagnostic efficacy in the differential diagnosis of viral pneumonia and bacterial pneumonia, suggesting that LUS technology may be used in the differential diagnosis of viral pneumonia and bacterial pneumonia.