ImportanceLength of hospital stay (LOHS) is the main cost-determining factor of hospitalization for stroke patients. However, previous analyses involving LOHS did not consider confounding or indirect factors, or the effects of other factors on LOHS and inpatient costs.ObjectiveTo investigate the direct and indirect effects of LOHS on the hospitalization costs of inpatients with ischemic and hemorrhagic stroke.Design, setting, and participantsThis was a population-based, retrospective, and observational study that analyzed data acquired from the Nationwide Inpatient Sample between 2015 and 2020 relating to ischemic and hemorrhagic stroke in Ningxia, China.Main outcomes and measuresHospitalizations were identified by the International Classification of Diseases 10th Revision (ICD-10). Inpatient costs were described by the median M (P25, P75). We used a quantile regression model to estimate the linear relationships between a group of independent variables X and the quantile of the explained variable hospitalization cost (Y). A structural equation model (SEM) was then used to investigate the direct and indirect effects of LOHS on inpatient costs.ResultsThe study included 129,444 patients with ischemic stroke and 15,525 patients with hemorrhagic stroke. The median LOHS was 10 (8–13) days for ischemic stroke and 15 (10–22) days for hemorrhagic stroke. The median M (P25, P75) of inpatient costs was $1020 (742–1545) for ischemic stroke and 2813 (1576–6191) for hemorrhagic stroke. The total effect of LOHS on inpatient costs was 0.795 in patients with ischemic stroke. The effect of yearof discharge (X4) and CCI (X8) on inpatient costs was dominated by an indirect effect through the LOHS. The indirect effect was −0.071 (84.52% of the total effect value) and 0.034 (69.39% of the total effect value), respectively. The total effect of LOHS on inpatient costs in patients with hemorrhagic stroke was 0.754. The influence of CCI on inpatient costs was dominated by an indirect effect through LOHS; the indirect effect value was −0.028 (77.78% of the total effect value). The payment type, surgery, method of discharge, and hospital level also exerted an impact on inpatient costs by direct and indirect effects through the LOHS.Conclusions and relevanceLength of hospital stay (LOHS) was identified as the main factor influencing hospitalization costs. However, other social factors were shown to indirectly influence hospitalization costs through the LOHS. Taking effective measures to further reduce hospitalization costs remains an effective way to control hospitalization costs for stroke patients.