  We aim at extracting the transmission spectrum of the HI Balmer lines of the
ultra-hot Jupiter (UHJ) KELT-20b/MASCARA-2b from observations and to further
compare the results with what obtained through forward modelling accounting for
non-local thermodynamic equilibrium (NLTE) effects. We extract the line
profiles from six transits obtained with the HARPS-N high-resolution
spectrograph attached to the Telescopio Nazionale Galileo telescope. We compute
the temperature-pressure (TP) profile employing the helios code in the lower
atmosphere and the Cloudy NLTE code in the middle and upper atmosphere. We
further use Cloudy to compute the theoretical planetary transmission spectrum
in LTE and NLTE for comparison with observations. We detected the Halpha
(0.79+/-0.03%; 1.25 Rp), Hbeta (0.52+/-0.03%; 1.17 Rp), and Hgamma
(0.39+/-0.06%; 1.13 Rp) lines, while we detected the Hdelta line at almost 4
sigma (0.27+/-0.07%; 1.09 Rp). The models predict an isothermal temperature of
about2200 K at pressures >10^-2 bar and of about 7700 K at pressures <10^-8
bar, with a roughly linear temperature rise in between. In the middle and upper
atmosphere, the NLTE TP profile is up to about 3000 K hotter than in LTE. The
synthetic transmission spectrum derived from the NLTE TP profile is in good
agreement with the observed HI Balmer line profiles, validating our obtained
atmospheric structure. Instead, the synthetic transmission spectrum derived
from the LTE TP profile leads to significantly weaker absorption compared to
the observations. Metals appear to be the primary agents leading to the
temperature inversion in UHJs and the impact of NLTE effects on them increases
the magnitude of the inversion. We find that the impact of NLTE effects on the
TP profile of KELT-20b/MASCARA-2b is larger than for the hotter UHJ KELT-9b,
and thus NLTE effects might be relevant also for planets cooler than
KELT-20b/MASCARA-2b.
