  We present an analysis of the Lyman continuum (LyC) escape fraction based on
a physically motivated model, and applied to galaxies of the Illustris TNG50
simulation in the redshift range $z=5.2-20$. Our study reveals a bimodal nature
of LyC escape, which is associated either to (a) high metallicity
($10^{-3.5}<Z<10^{-2}$), low mass ($M_\star<10^7\mathrm{M}_\odot$) galaxies
exhibiting extended star formation, with photons escaping primarily from the
outer regions of the galactic disk ({\it ext}-mode), or (b) low metallicity
($Z<10^{-3}$), moderately massive galaxies ($M_\star<10^8\mathrm{M}_\odot$)
with localized LyC escape originating from small central regions of high star
formation ({\it loc}-mode). While the {\it loc}-mode is present at all
redshifts under investigation, the {\it ext}-mode becomes prominent in small
galaxies at later cosmic times, once sufficient metal enrichment has occurred.
Building on these findings, we develop an analytical fitting formula to
determine the escape fraction of galaxies based on their stellar and gas mass,
as well as redshift, providing a valuable subgrid modelling tool for future
studies.
