Galaxy sizes correlate with many other important properties of galaxies, and the cosmic evolution of galaxy sizes is an important observational diagnostic for constraining galaxy evolution models. The effective radius is probably the most widely used indicator of galaxy size. We used the TNG50-SKIRT Atlas to investigate the wavelength dependence of the effective radius of galaxies at optical and near-infrared (NIR) wavelengths. We find that, on average, the effective radius in every band exceeds the stellar mass effective radius, and that this excess systematically decreases with increasing wavelength. The optical g -band (NIR $ K s $-band) effective radius is on average 58<!PCT!> (13<!PCT!>) larger than the stellar mass effective radius. Effective radii measured from dust-obscured images are systematically larger than those measured from dust-free images, although the effect is limited (8.7<!PCT!> in the g -band, 2.1<!PCT!> in the $ K s $-band). We find that stellar population gradients are the dominant factor (about 80<!PCT!>) in driving the wavelength dependence of the effective radius, and that differential dust attenuation is a secondary factor (20<!PCT!>). Comparing our results to recent observational data, we find offsets in the absolute values of the median effective radii, up to 50<!PCT!> for the population of blue galaxies. We find better agreement in the slope of the wavelength dependence of the effective radius, with red galaxies having a slightly steeper slope than green--blue galaxies. Comparing our effective radii with those of galaxies from the Siena Galaxy Atlas in separate bins in $ z $-band absolute magnitude and $ g z $ colour, we find excellent agreement for the reddest galaxies, but again significant offsets for the blue populations: up to 70<!PCT!> for galaxies around $M_z=-21.5$. This difference in median effective radius for the bluer galaxies is most probably due to intrinsic differences in the morphological structure of observed and TNG50 simulated galaxies. Finally, we find that the median effective radius in any broadband filter increases systematically with decreasing $ u r $ colour and with increasing galaxy stellar mass, total SFR, sSFR, and dust-to-stellar-mass ratio. For the slope of the wavelength dependence of $R_ e $, however, there does not seem to be a systematic, monotonic correlation with any of these global properties.