When two bodies with different temperatures are brought into contact, heat flows from the body with the higher temperature to the one with the lower temperature until a mixing temperature $T_\mathrm{M}$ is reached after some time.
The energy released by body 1 must therefore be exactly equal to the energy absorbed by body 2:
$$
-\Delta Q_1 = \Delta Q_2
$$
The minus sign indicates the direction of heat flow. Using the heat capacity formula:
$$
\Delta Q = cm\Delta T
$$
we get:
$$
-m_1c_1(T_1 - T_\mathrm{M}) = m_2c_2(T_2 - T_\mathrm{M})
$$
Expanding both brackets and solving for $T_\mathrm{M}$, we obtain the formula for calculating the mixing temperature:
$$
\boxed{T_\mathrm{M} = \frac{m_1c_1T_1 + m_2c_2T_2}{m_1c_1 + m_2c_2}}
$$
This relation is also known as Richmann's mixing rule, named after the physicist Georg Wilhelm Richmann.
Important: All temperatures must be converted to Kelvin when performing calculations, especially if given in degrees Celsius or another unit.