Unit content
Grand canonical ensemble and grand potential
When a system can exchange both energy and particles with a large reservoir, equilibrium statistical mechanics describes it with the grand canonical ensemble.
The controlled macroscopic variables are temperature $T$, volume $V$ and chemical potential $\mu$, while the particle number $N$ is allowed to fluctuate.
A microstate $i$ with energy $E_i$ and particle number $N_i$ receives statistical weight
$$e^{-\beta(E_i-\mu N_i)},$$
where
$$\beta=\frac{1}{k_BT}.$$
The normalization is the grand partition function
$$\boxed{\Xi=\sum_i e^{-\beta(E_i-\mu N_i)}},$$
so the probability of microstate $i$ is
$$P_i=\frac{e^{-\beta(E_i-\mu N_i)}}{\Xi}.$$
The chemical-potential term matters because microstates with different particle numbers exchange particles with the reservoir. Positive or negative changes in $N_i$ therefore alter the reservoir-system thermodynamic balance as well as the microstate energy.
Mean particle number
Differentiating the grand partition function gives
$$\boxed{\langle N\rangle=\frac{1}{\beta}\left(\frac{\partial\ln\Xi}{\partial\mu}\right)_{T,V}}.$$
Thus the ensemble predicts an average particle number even though individual microstates can contain different $N$.
Grand potential
The thermodynamic potential associated with fixed $T$, $V$ and $\mu$ is the grand potential
$$\boxed{\Omega=-k_BT\ln\Xi}.$$
For a homogeneous equilibrium system under ordinary conditions,
$$\Omega=-pV.$$
The grand canonical ensemble is especially useful for open subsystems, adsorption, quantum gases and particle populations whose number is not fixed. It supplies the statistical-mechanical machinery behind chemical potential rather than defining chemical potential for the first time.