# How is it possible to have Fermi energy in the middle of bandgap for semiconductors?

Actually, I'm still a beginner for Fermi energy and its related band theory. Typically in an intrinsic semiconductor the Fermi energy or the highest occupied energy level of electrons at $0\, \mathrm K$ is placed at the middle of the band gap. How is this possible if the band gap doesn't hold any allowed energy state?

Consider a system with discrete energies, with $N$ occupied levels and at $0\, \mathrm K$. The Fermi-Dirac distribution is given by $$n=\frac{1}{\exp\left(\frac{E-E_F}{kT}\right)+1},$$ where $E_F$ is the Fermi energy. The occupation of the $N$th level is $1$ and from the above equation this gives $E_N<E_F$ when taking the limit $T\rightarrow 0$. On the other hand, the occupation of the $(N+1)$th level is $0$ which leads to $E_{N+1}>E_F$. Hence, $$E_N<E_F<E_{N+1}.$$ In particular, for insulators and semiconductors the Fermi level shall be in the gap between the valence band (whose last level is $E_N$) and the conduction band (whose first level is $E_{N+1}$). Note that only for continuum levels the Fermi energy is equivalent to the energy of the highest occupied level at zero temperature.