determine degeneracy of energy levels
In this case, we say that their corresponding shared energy eigenvalue is degenerate. It is therefore often convenient to have a the concept of the energy levels. The degeneracy $g_n$ of the energy level $E_n$ is defined as the number of distinct energy eigenvalues $\epsilon_m$ for which $\epsilon_m=E_n$.For simplicity, we assume that none of the levels is infinitely degenerate so that $g_n\geq 1$ is integer for all $n$.owever, noting that whenever there is degeneracy, sum of the terms in the sum will be the same, we can rewrite the partition function as a sum over levels \begin{align} Z = \sum_{n} g_n e^{-\beta E_n} \end{align} The degeneracy factor is precisely what counts the number of terms in the sum that have the same energy.