The clinical symptoms of ≤ 5 cm gastric stromal tumor (GST) and gastric schwannoma (GS) are similar, but the treatment regimens are different. This study explored the value of computed tomography (CT) combined with machine learning (ML) algorithms to find the best model to discriminate them. A total of 126 patients with GST ≤ 5 cm and 35 patients with GS ≤ 5 during 2013–2022 were included. CT imaging features included qualitative data (tumor location, growth pattern, lobulation, surface ulcer status, necrosis, calcification, and surrounding lymph nodes) and quantitative data [long diameter (LD); short diameter (SD); LD/SD ratio; degree of enhancement (DE); heterogeneous degree (HD)]. Patients were randomly divided into a training set (n = 112) and test set (n = 49) using 7:3 stratified sampling. The univariate and multivariate logistic regression analysis were used to identify independent risk factors. Five ML algorithms were used to build prediction models: Support Vector Machine, k-Nearest Neighbor, Random Forest, Extra Trees, and Extreme Gradient Boosting Machine. The analysis identified that HDv, lobulation, and tumor growth site were independent risk factors (P < 0.05). We should focus on these three imaging features of tumors, which are relatively easy to obtain. The area under the curve for the SVM, KNN, RF, ET, and XGBoost prediction models were, respectively, 0.790, 0.895, 0.978, 0.988, and 0.946 for the training set, and were, respectively, 0.848, 0.892, 0.887, 0.912, and 0.867 for the test set. The CT combined with ML algorithms generated predictive models to improve the differential diagnosis of ≤ 5 cm GST and GS which has important clinical practical value. The Extra Trees algorithm resulted in the optimal model.