  We use the magnetic-hydrodynamical simulation TNG50 to study the evolution of
barred massive disc galaxies. Massive spiral galaxies are already present as
early as $z=4$, and bar formation takes place already at those early times. The
bars grow longer and stronger as the host galaxies evolve, with the bar sizes
increasing at a pace similar to that of the disc scale lengths. The bar
fraction mildly evolves with redshift for galaxies with
$M_{*}\geq10^{10}M\odot$, being greater than $\sim40\%$ at $0.5<z<3$ and
$\sim30\%$ at $z=0$. When bars larger than a given physical size ($\geq 2\,\rm
kpc$) or the angular resolution limit of twice the I-band angular PSF FWHM of
the HST are considered, the bar fraction dramatically decreases with increasing
redshift, reconciling the theoretical predictions with observational data. We
find that barred galaxies have an older stellar population, lower gas fractions
and star formation rates than unbarred galaxies. In most cases, the discs of
barred galaxies assembled earlier and faster than the discs of unbarred
galaxies. We also find that barred galaxies are typical in haloes with larger
concentrations and smaller spin parameters than unbarred galaxies. Furthermore,
the inner regions of barred galaxies are more baryon-dominated than those of
unbarred galaxies but have comparable global stellar mass fractions. Our
findings suggest that the bar population could be used as a potential tracer of
the buildup of disc galaxies and their host haloes. With this paper, we release
a catalogue of barred galaxies in TNG50 at $6$ redshifts between $z=4$ and
$z=0$.
