This paper explores the application of the XGBoost machine learning model for forecasting the hourly thermal demand in District Heating Systems, aligning with the European Union’s ambitious sustainability targets as outlined in the Renewable Energy Directive (RED) and the Energy Efficiency Directive (EED). Accurate forecasts of thermal demand are crucial for enhancing the efficiency of district heating systems through the integration of renewable energy sources and the adoption of waste heat recovery, thereby contributing significantly to achieving climate neutrality by the year 2050. This study presents a dual approach to forecasting: at the individual building level, and at an aggregated level by considering the average characteristics of the served building stock. Through a comprehensive case study of the Turin district heating system (Italy), which comprises hourly data from approximately 200 heat exchange substations across nine heating seasons, this research evaluates the comparative effectiveness of different forecasting approaches in terms of prediction accuracy and computational efficiency. The findings aim to guide district heating operators and planners in selecting the most suitable forecasting approach based on available input information, desired accuracy, and computational constraints, contributing to the strategic planning and development of sustainable and efficient district heating systems.