The total length of stay (LOS) is one of the biggest determinators of overall care costs associated with total knee arthroplasty (TKA). An accurate prediction of LOS could aid in optimizing discharge strategy for patients in need and diminishing healthcare expenditure. The aim of this study was to predict LOS following TKA using machine learning models developed on a national-scale patient cohort. The ACS-NSQIP database was queried to acquire 267,966 TKA cases from 2013 to 2020. Four machine learning models-artificial neural network (ANN), random forest, histogram-based gradient boosting, and k-nearest neighbor were trained and tested on the dataset for the prediction of prolonged LOS (LOS exceeded the 75th of all values in the cohort). The model performance was assessed by discrimination (area under the receiver operating characteristic curve [AUC]), calibration, and clinical utility. ANN delivered the best performance among the four models. ANN distinguished prolonged LOS in the study cohort with an AUC of 0.71 and accurately predicted the probability of prolonged LOS for individual patients (calibration slope: 0.82; calibration intercept: 0.03; Brier score: 0.089). All models demonstrated clinical utility by generating positive net benefits in decision curve analyses. Operation time, pre-operative transfusion, pre-operative laboratory tests (hematocrit, platelet count, and white blood cell count), and BMI were the strongest predictors of prolonged LOS. ANN demonstrated modest discrimination capacity and excellent performance in calibration and clinical utility for the prediction of prolonged LOS following TKA. Clinical application of the machine learning models has the potential to improve care coordination and discharge planning for patients at high risk of extended hospitalization after surgery. Incorporating more relevant patient factors may further increase the models' prediction strength.