Abstract Background Length of hospital stay (LOS) is considered a key process that has a clinical, economic, and organizational impact representative of the quality of care. In particular, in patients with heart failure (HF), which is a life–threatening multifactorial syndrome and a major public health problem, when a prolonged LOS (PLOS) occurs, frequent readmission and high mortality are common, with worrying consequences for health systems. Although the LOS is often explained by standard medical data (e.g., comorbidities), it may depend on many other patient characteristics. Therefore, considering additional elements collected in electronic health records (EHRs) could be crucial to predict the occurrence of a LOS and correctly estimating this risk. The aim of this study is to demonstrate the predictive power of clinical and organizational data collected through an EHR on LOS in HF patients. Methods A descriptive, retrospective study was conducted in an Italian university hospital. Data related to HF inpatients consecutively admitted across 1 year were collected from the hospital’s HER. PLOS was defined as a stay ≥ 14 days. Sociodemographic data, administrative data, and clinical data (such as the number of active medical problems, the number of medications, frailty, and nursing dependency), were tested in a predictive model as potential determinants of LOS. Results A total of 608 HF patients were included. The mean age of patients was 76 ± 13.06 years (range: 23–102); 61.5% were male. Prolonged LOS was found in 25.2% of patients. The univariable linear regression model explained 10.2% of LOS variance. Being female, living without social support, having an increased number of previous admissions and nursing dependency, being dependent on functional status, having a worse behavior pattern and mobility, and experiencing a sensory deficit were significant determinants (p < .05) of LOS. Conclusion The inclusion of EHRs data in addition to clinical variables, can help clinicians and researchers to improve the predictive ability on LOS, ensuring its early identification and ultimately enhancing the patients’ health outcomes through the implementation of targeted interventions.