In the canonical ensemble the partition function is $$ \begin{equation*} Z=\sum_{i=1}^{M}e^{-\beta E_i}, \end{equation*} $$ where the sum extends over all microstates \( M \).