BackgroundRecently, crowding in emergency departments (EDs) has become a recognised critical factor impacting global public healthcare, resulting from both the rising supply/demand mismatch in medical services and the paucity of hospital beds available in inpatients units and EDs. The length of stay in the ED (ED-LOS) has been found to be a significant indicator of ED bottlenecks. The time a patient spends in the ED is quantified by measuring the ED-LOS, which can be influenced by inefficient care processes and results in increased mortality and health expenditure. Therefore, it is critical to understand the major factors influencing the ED-LOS through forecasting tools enabling early improvements.MethodsThe purpose of this work is to use a limited set of features impacting ED-LOS, both related to patient characteristics and to ED workflow, to predict it. Different factors were chosen (age, gender, triage level, time of admission, arrival mode) and analysed. Then, machine learning (ML) algorithms were employed to foresee ED-LOS. ML procedures were implemented taking into consideration a dataset of patients obtained from the ED database of the “San Giovanni di Dio e Ruggi d’Aragona” University Hospital (Salerno, Italy) from the period 2014–2019.ResultsFor the years considered, 496,172 admissions were evaluated and 143,641 of them (28.9%) revealed a prolonged ED-LOS. Considering the complete data (48.1% female vs. 51.9% male), 51.7% patients with prolonged ED-LOS were male and 47.3% were female. Regarding the age groups, the patients that were most affected by prolonged ED-LOS were over 64 years. The evaluation metrics of Random Forest algorithm proved to be the best; indeed, it achieved the highest accuracy (74.8%), precision (72.8%), and recall (74.8%) in predicting ED-LOS.ConclusionsDifferent variables, referring to patients’ personal and clinical attributes and to the ED process, have a direct impact on the value of ED-LOS. The suggested prediction model has encouraging results; thus, it may be applied to anticipate and manage ED-LOS, preventing crowding and optimising effectiveness and efficiency of the ED.