Statistical mechanics is the application of statistics, which includes mathematical tools for dealing with large populations, to the field of mechanics, which is concerned with the motion of particles or objects when subjected to a force. It provides a framework for relating the microscopic properties of individual atoms and molecules to the macroscopic or bulk properties of materials that can be observed in every day life, therefore explaining thermodynamics as a natural result of statistics and mechanics (classical and quantum). In particular, it can be used to calculate the thermodynamic properties of bulk materials from the spectroscopic data of individual molecules. Microscopic entropy, the Boltzmann factor and the partition function
At the heart of statistical mechanics lies Boltzmann's definition of entropy of a physical system:  The entropy of a macroscopic state is proportional to the logarithm of the number of microscopic states corresponding to it.
Boltzmann's proportionality constant is denoted k. See microcanonical ensemble. Let's introduce the standand β=1/kT. From this definition it is possible to deduce the fact that, if a system is in contact with a heat bath, the probability of a microstate of energy E is proportional to where the temperature T arises from the fact that the system is in equilibrium with the heat bath (see canonical ensemble). This quantity is called the Boltzmann factor. The probabilities of the various microstates must add to one, and the normalization factor is the partition function: where E_{i} is the energy of the ith microstate of the system. The partition function is a measure of the number of states accessible to the system at a given temperature. See derivation of the partition function for a proof of Boltzmann's factor and the form of the partition function from first principles. To sum up, the probability of finding a system at temperature T in a particular state with energy E_{i} is Connection with thermodynamics The partition function can be used to find the expected (average) value of any microscopic property of the system, which can then be related to macroscopic variables. For instance, the expected value of the microscopic energy E is interpreted as the microscopic definition of the thermodynamic variable internal energy (U)., and can be obtained by taking the derivative of the partition function with respect to the temperature. Indeed, implies, together with the interpretation of <E> as U, the following microscopic definition of internal energy: The entropy can be calculated by (see Shannon entropy) which implies that is the Free energy of the system or in other words, Having microscopic expressions for the basic thermodynamic potentials U (internal energy), S (entropy) and F (free energy) is sufficient to derive expressions for other thermodynamic quantities. The basic strategy is as follows. There may be an intensive or extensive quantity that enters explicitly in the expression for the microscopic energy E_{i}, for instance magnetic field (intensive) or volume (extensive). Then, the conjugate thermodynamic variables are derivatives of the internal energy. For instance, the macroscopic magnetization (extensive) is the derivative of U with respect to the (intensive) magnetic field, and the pressure (intensive) is the derivative of U with respect to volume (extensive).
Variable particle number That was the version for systems which don't allow an exchange of matter. Otherwise, if matter can be exchanged and particle number is conserved, we would have to introduce chemical potentials, μ_{j}, j=1,...,n and replace the partition function with where N_{ij} is the number of j^{th} species particles in the i^{th} configuration. Sometimes, we also have other variables to add to the partition function, one corresponding to each conserved quantity. Most of them, however, can be safely interpreted as chemical potentials. In most condensed matter systems, things are nonrelativistic and mass is conserved. However, most condensed matter systems of interest also conserve particle number approximately (metastably) and the mass (nonrelativistically) is none other than the sum of the number of each type of particle times its mass. Mass is inversely related to density, which is the conjugate variable to pressure. For the rest of this article, we will ignore this complication and pretend chemical potentials don't matter. See grand canonical ensemble.
Further development The treatment in this section assumes no exchange of matter (i.e. fixed mass and fixed particle numbers). However, the volume of the system is variable which means the density is also variable. This probability can be used to find the average value, which corresponds to the macroscopic value, of any property, J, that depends on the energetic state of the system by using the formula: where < J > is the average value of property J. This equation can be applied to the internal energy, U: Subsequently, these equations can be combined with known thermodynamic relationships between U and V to arrive at an expression for pressure in terms of only temperature, volume and the partition function. Similar relationships in terms of the partition function can be derived for other thermodynamic properties as shown in the following table. The last entry needs clarification. We are NOT working with a grand canonical ensemble here. It is often useful to consider the energy of a given molecule to be distributed among a number of modes. For example, translational energy refers to that portion of energy associated with the motion of the center of mass of the molecule. Configurational energy refers to that portion of energy associated with the various attractive and repulsive forces between molecules in a system. The other modes are all considered to be internal to each molecule. They include rotational, vibrational, electronic and nuclear modes. If we assume that each mode is independent (a very questionable assumption!!!!!) the total energy can be expressed as the sum of each of the components: Where the subscripts t, c, n, e, r, and v correspond to translational, configurational, nuclear, electronic, rotational and vibrational modes, respectively. The relationship in this equation can be substituted into the very first equation to give: 
Thus a partition function can be defined for each mode. Simple expressions have been derived relating each of the various modes to various measurable molecular properties, such as the characteristic rotational or vibrational frequencies. Expressions for the various molecular partition functions are shown in the following table. Nuclear   Electronic   vibrational   rotational (linear)   rotational (nonlinear)   Translational   Configurational (ideal gas)   These equations can be combined with those in the first table to determine the contribution of a particular energy mode to a thermodynamic property. For example the "rotational pressure" could be determined in this manner. The total pressure could be found by summing the pressure contributions from all of the individual modes, ie: Grand canonical ensemble Let's rework everything using a grand canonical ensemble this time. The volume is left fixed and does not figure in at all in this treatment. As before, j is the index for those particles of species j and i is the index for microstate i: See also
