  We study the relation between the UV-slope, $\beta$, and the ratio between
the infrared- and UV-luminosities (IRX) of galaxies from TNG50, the latest
installment of the IllustrisTNG galaxy formation simulations. We select 7280
star-forming main-sequence (SFMS) galaxies with stellar mass $10^9M_\odot$ at
redshifts $0 \leq z \leq 4$ and perform radiative transfer with SKIRT to model
effects of interstellar medium dust on the emitted stellar light. Assuming a
Milky Way (MW) dust type and a dust-to-metal ratio of 0.3, we find that TNG50
SFMS galaxies generally agree with observationally-derived IRX-$\beta$
relations at $z \lesssim 1$. However, we find a redshift-dependent systematic
offset with respect to empirically-derived local relations, with the TNG50
IRX-$\beta$ relation shifting towards lower $\beta$ and steppening at higher
redshifts. This is partially driven by variations in the dust-uncorrected
UV-slope of galaxies, due to different star-formation histories of galaxies
selected at different cosmic epochs; we suggest the remainder of the effect is
caused by differences in the effective dust attenuation curves (EDACs) of
galaxies as a function of redshift. We find a typical galaxy-to-galaxy
variation of 0.3 dex in IRX at fixed $\beta$, correlated with intrinsic galaxy
properties: galaxies with higher star-formation rates, star-formation
efficiencies, gas metallicities and stellar masses exhibit larger IRX values.
We demonstrate a degeneracy between stellar age, dust geometry and dust
composition: $z=4$ galaxies with a Small Magellanic Cloud dust type follow the
same IRX-$\beta$ relation as low-redshift galaxies with MW dust. We provide a
redshift-dependent fitting function for the IRX-$\beta$ relation for MW dust
based on our models.
