The grand canonical ensemble allows particle number N to fluctuate while the chemical potential μ, volume V, and temperature T remain fixed. Microstates have weights proportional to exp[−(E − μN)/kT]. This ensemble is natural for systems in contact with a particle reservoir and is essential for describing quantum gases.
In the canonical ensemble (which you have already studied), the system is in thermal contact with a heat bath — energy can flow in and out, but the number of particles N is fixed. This works well for many classical systems, but it becomes awkward when particles themselves can move between the system and its environment: gases in open containers, electrons in a metal connected to a lead, or photons in a cavity that can be absorbed and re-emitted. For these situations, the grand canonical ensemble is the natural framework. It keeps temperature T and volume V fixed, but allows the particle number N to fluctuate around a mean value ⟨N⟩. The control variable for the particle exchange is the chemical potential μ.
The statistical weight for a microstate with energy E and particle number N is the grand canonical Boltzmann factor: exp[−(E − μN)/kT]. You can read this as an extension of the canonical weight exp[−E/kT]. The extra term μN in the exponent accounts for the "cost" of having N particles in the system. When μ is large and positive, states with many particles are strongly favored. When μ is negative and large in magnitude, states with few particles are favored. The chemical potential thus plays the same role for particle number that temperature plays for energy: it is the intensive variable that, when equal between system and reservoir, signals equilibrium with respect to particle exchange.
The grand partition function is Z_G = Σ_{N,s} exp[−(E_s(N) − μN)/kT], where the sum runs over all particle numbers N and all energy microstates s at each N. From Z_G you can derive all thermodynamic quantities: average particle number ⟨N⟩ = kT ∂(ln Z_G)/∂μ, average energy, pressure, and entropy. The grand potential Ω = −kT ln Z_G is the natural free energy for this ensemble, analogous to the Helmholtz free energy F = −kT ln Z in the canonical ensemble.
The grand canonical ensemble is indispensable for quantum gases precisely because quantum statistics — Fermi-Dirac and Bose-Einstein — emerge most cleanly here. For a quantum gas, you cannot think of particles as distinguishable; the relevant states are occupation number configurations, not labeled-particle configurations. In the grand canonical ensemble, each single-particle state can be treated independently, with its own occupation number n_k fluctuating between 0 and 1 (fermions) or 0 and ∞ (bosons). The mean occupation of state k turns out to be ⟨n_k⟩ = 1/[exp((ε_k − μ)/kT) ± 1], which you will recognize as the Fermi-Dirac and Bose-Einstein distributions. These famous results flow directly from the grand canonical framework — which is why this ensemble is the entry point to quantum statistical mechanics.