One common way to motivate the canonical ensemble is to consider the system of interest to be placed into a much larger system, the "heat bath", with which it is allowed to exchange energy. Then if we let ##W(E)## be the number of microstates for the composite system with total energy ##E##, we can calculate it this way:
##W_{total}(E) = \sum_{\varepsilon} W_{hb}(E-\varepsilon) W_{s}(\varepsilon)##
where ##W_{hb}(E-\varepsilon)## is the number of microstates of the heat bath with energy ##E-\varepsilon## and ##W_s(\varepsilon)## is the number of microstates of the system of interest with energy ##\varepsilon##, and where ##W_{total}(E)## is the number of states of the composite system. Letting the entropy ##S## be defined via: ##S = k \ln W##, we have:
##e^{S_{total}/k} = \sum_{\varepsilon} e^{(S_{hb}(E - \varepsilon) + S_{s}(\varepsilon))/k}##
At this point, we assume that since the heat bath is much larger than the system of interest, most of the energy will be found in the heat bath. Then we can make the approximation:
##S_{hb}(E - \varepsilon) \approx S_{hb}(E) - \dfrac{\partial S_{hb}}{\partial E} \varepsilon##
Thermodynamically, ##\dfrac{\partial S_{hb}}{\partial E} \equiv \dfrac{1}{T_{hb}}## where ##T_{hb}## is the temperature of the heat bath. So we can write:
##e^{S_{total}/k} = e^{S_{hb}/k} \sum_{\varepsilon} e^{- \varepsilon/(kT)+ S_{s}(\varepsilon))/k}##
The probability of the small system having energy ##\varepsilon## (given that the total energy is ##E##) is proportional to the number of states of the composite system with total energy ##E## and subsystem energy ##\varepsilon##:
##P(E,\varepsilon) \propto e^{- \varepsilon/(kT)+ S_{s}(\varepsilon))/k} = e^{- (\varepsilon - S_{s} T)/(kT))}##