The Bose–Einstein distribution describes how indistinguishable bosons are distributed among available energy states at thermal equilibrium.

To derive the Bose–Einstein distribution, consider a system of fixed-volume containing \(n_i\) bosons occupying discrete single-particle energy levels \(E_i\), each with degeneracy \(g_i\), with no restriction on the number of bosons that can occupy a single state. The total number of bosons \(N\) and the total energy \(E\) of the system are
$$N=\sum_in_i\;\;\;\;\;\;\;\;31$$
$$E=\sum_in_iE_i\;\;\;\;\;\;\;\;32$$
where \(i=0,1,2,\cdots\)
Replicas of this system form a microcanonical ensemble, meaning that only configurations \(\{n_0,n_1,n_2,\cdots\}\) with the same fixed \(N\) and \(E\) are allowed.

Since any number of bosons can occupy the same single-particle state, the number of ways \(W_i\) to place \(n_i\) bosons among the \(g_i\) degenerate states at energy \(E_i\) is given by the stars-and-bars result:
$$W_i=\frac{(n_i+g_i-1)!}{(g_i-1)!n_1!}\;\;\;\;\;\;\;\;33$$
For example, if two bosons \((n_i=2)\) occupy three degenerate states (\(g_i=3\)), the possible occupation configurations are 200, 020, 002, 110, 101, or 011. Thus, there are six possible microstates, consistent with
$$W_i=\frac{(2+3-1)!}{(3-1)!2!}=6$$
It follows that the total number of microstates corresponding to a particular configuration is
$$W_i=\prod_iW_i\;\;\;\;\;\;\;\;34$$
For macroscopic systems, distinct single-particle energy levels are often extremely closely spaced. Consequently, many distinct energy levels can fall within a small energy interval. For the purposes of counting, these closely spaced levels may be treated as approximately degenerate, so that the interval contains a very large number \(g_i\) of approximately degenerate single-particle states. Taking the natural logarithm of eq34 and substituting eq33 gives:
$$lnW=lnW_1+lnW_2+\cdots=\sum_ilnW_i=\sum_iln\frac{(n_i+g_i-1)!}{(g_i-1)!n_1!}$$
where \(g_i-1\approx g_i\) because \(g_i\) is large.
Using Stirling’s approximation. where \(lnx!=xlnx-x\), yields:
$$lnW=\sum_i[(n_i+g_i)ln(n_i+g_i)-n_ilnn_i-g_ilng_i]\;\;\;\;\;\;\;\;35$$

The possible configurations that define the microcanonical ensemble are restricted by eq31 and eq32. For example, the configurations \(\{N,0,0,\cdots\}\) and \(\{N-1,1,0,\cdots\}\) generally have different total energies and therefore cannot both belong to the same microcanonical ensemble. However, different configurations can have the same total energy and therefore can belong to the same microcanonical ensemble (see above diagram for an illustration). In such cases, all microstates corresponding to the allowed configurations satisfying the fixed \(N\) and \(E\) constraints are equally probable. The most probable equilibrium configuration is therefore the one with the largest number of ways of achieving it, i.e. the one whose \(W\) (or \(lnW\)) is maximal.
The total differential of \(lnW\) is:
$$dlnW=\sum_i\biggr(\frac{\partial lnW}{\partial n_i}\biggr)_{all\;other\;n\neq n_i}dn_i\;\;\;\;\;\;\;\;36$$
Hence, we want to solve for \(dlnW=0\). With reference to Step 2 of the derivation of the Boltzmann distribution using the Lagrange method of undetermined multipliers, eq36 becomes:
$$\sum_i\biggr[\biggr(\frac{\partial lnW}{\partial n_i}\biggr)-a-bE_i\biggr]dn_i=0\;\;\;\;\;\;\;\;37$$
where we have chosen minus signs for the 2nd and 3rd terms for convenience.
Since \(dn_i\) varies independently, eq37 holds only if each coefficient is zero:
$$\biggr(\frac{\partial lnW}{\partial n_i}\biggr)-a-bE_i=0\;\;\;\;\;\;\;\;38$$
Substituting eq35 into eq38, and noting that \(g_i\) does not depend on \(n_i\), gives:
$$\sum_j\biggr[\frac{\partial(n_j+g_j)ln(n_j+g_j)}{\partial n_i}-\frac{\partial n_jlnn_j}{\partial n_i}\biggr]-a-bE_i=0\;\;\;\;\;\;\;\;39$$
where we have changed the summation index from \(i\) to \(j\) in eq39 to distinguish the summation variable from the differentiation variable.
All terms in the summation of eq39 goes to zero except when \(j=i\). So,
$$\frac{\partial(n_i+g_i)ln(n_i+g_i)}{\partial n_i}-\frac{\partial n_ilnn_i}{\partial n_i}-a-bE_i=0$$
Carrying out the differentiation and rearranging the result yields:
$$n_i=\frac{g_i}{e^{a+bE_i}-1}\;\;\;\;\;\;\;\;40$$
As mentioned above, \(n_i\) is the number of bosons occupying the energy level \(E_i\). To transform eq40 into a probability distribution, we write:
$$n_i=f_ig_i\;\;\;\;\;\;\;\;41$$
where \(f_i\) is the average or expected occupation number per degenerate state at energy \(E_i\). Thus, \(f_ig_i\) gives the total number of bosons occupying \(E_i\).
Substituting eq41 into eq40 gives:
$$f_i=\frac{1}{e^{a+bE_i}-1}\;\;\;\;\;\;\;\;42$$
The evaluation of the Lagrange multipliers \(a\) and \(b\) proceeds in exactly the same way as for the Fermi-Dirac distribution, resulting in \(b=\frac{1}{kT}\) and \(a=-\frac{\mu}{kT}\). Therefore,
$$f_i=\frac{1}{e^{\frac{E_i-\mu}{kT}}-1}\;\;\;\;\;\;\;\;43$$
which is the Bose–Einstein distribution function.
For bosons, the chemical potential \(\mu\) must satisfy \(\mu\leq E_0\), where \(E_0\) is the lowest single-particle energy level. This condition ensures that the denominator in eq43 does not become negative or zero. In particular, when the ground-state energy is chosen to be zero (\(E_0=0\)), the chemical potential satisfies \(\mu\leq 0\). As \(\mu\) approaches the ground-state energy from below (\(\mu\rightarrow 0^-\)), the occupation of the lowest-energy state can become extremely large because
$$E_0-\mu\rightarrow 0^+\implies e^{\frac{E_0-\mu}{kT}}\rightarrow 1^+\implies f_0\rightarrow\frac{1}{0^+}\rightarrow\infty$$
This behaviour is associated with Bose–Einstein condensation, in which a macroscopic number of bosons can occupy the lowest-energy quantum state.
For photons \(\gamma\), the situation is slightly different. Although photons are bosons, their number is not conserved in thermal equilibrium because they can be freely created and absorbed through interactions with matter, e.g. \(atom+\gamma\rightarrow atom^*\). The chemical potential of a species is defined as the change in Gibbs free energy \(G\) with respect to the change in the number of particles of that species \(n_i\), while the temperature, pressure and numbers of all other species are held constant: \(\mu_i=\biggr(\frac{\partial G}{\partial n_i}\biggr)_{T,P,n_{j\neq i}}\). Since \(G\) is a minimum at equilibrium, \(\mu_i=\biggr(\frac{\partial G}{\partial n_i}\biggr)_{T,P,n_{j\neq i}}=0\) if \(n_i\) is free to vary. If \(n_i\) is constrained and not free to vary, then \(\mu_i=\biggr(\frac{\partial G}{\partial n_i}\biggr)_{T,P,n_{j\neq i}}\) may or may not be zero. Consequently, the chemical potential of photons is always zero at thermodynamic equilibrium, and eq43 becomes
$$f_i=\frac{1}{e^{\frac{E_i}{kT}}-1}$$
which is the occupation factor underlying Planck’s blackbody radiation law, showing that blackbody radiation is fundamentally a quantum-statistical phenomenon.