Definition of Temperature in Physics
Definition1 2
Suppose there is a system with energy $E$. Let the number of microstates for $E$ be $\Omega (E) = \Omega$. Then the $T$ satisfying
$$ \dfrac{1}{k_{B} T} := \dfrac{d \ln ( \Omega )}{d E } $$
is defined as the temperature of the system. (Here, $k_{B}$ is the Boltzmann constant.)
Microstates and Macrostates
In statistical mechanics, the macrostate and microstate of a system are, for example, concepts similar to the following. Suppose there are four coins in a box. If you shake the box vigorously and open it, heads and tails will be determined at random. Representing heads as white and tails as dark gray, the states of the coins appear as follows.

Looking only at the number of heads, there are a total of $5$ cases, from $0$ to $4$, and this is called the number of macrostates $S$. On the other hand, if we count whether each individual coin is heads or tails, then as is well known there are $2^4=16$ cases, and this is called the number of microstates $\Omega$.
Naturally, if the number of microstates $\Omega$ is large, the corresponding macrostate is more likely to be observed. In the situation above, if we denote the number of microstates in which $k$ out of $n$ coins are heads by $\Omega (k, n-k)$, the case with the largest number of microstates is $\Omega (2,2) = 6$, so the case with two heads and two tails is the most likely to be observed.
Derivation
The definition of temperature is naturally derived in the process of finding the macrostate of two interacting systems. Consider a closed system $X$ as below.

$X$ is divided into $A$ and $B$. Let the internal energies of $A$ and $B$ be $E_{A}$ and $E_{B}$, respectively. In terms of the coin example above, $A$ and $B$ are collections of particular coins, and $E_{A}$ and $E_{B}$ are each the number of coins showing heads.
Assume that all microstates are equally probable and that $A$ and $B$ have interacted sufficiently (or that enough time has passed), so that the two systems are in thermal equilibrium. The energy of the whole system equals $E_{X} = E_{A} + E_{B}$. The number of microstates of the whole system $X$ is given by the product of the number of microstates available to $A$, $\Omega (E_{A})$, and the number of microstates available to $B$, $\Omega (E_{B})$.
$$ \begin{equation} \Omega_{X} (E_{X}) = \Omega_{A} (E_{A}) \Omega_{B} (E_{B}) \end{equation} $$
Then it is natural to accept that the macrostate at thermal equilibrium is the one for which the value of the above equation is largest. In fact, the number of microstates corresponding to the macrostate at thermal equilibrium is said to be overwhelmingly larger than in other cases. If we think of the number of microstates $\Omega$ as a normal distribution, it is natural to accept that the point where the derivative of $(1)$ becomes $0$ is the maximum.
However, in fact, the energy of a particle is not a continuous value but is quantized. Therefore the total energy of the system $E_{X}$ also takes discrete values. But in thermal physics, the number of particles in the systems being dealt with is enormously large, so the number of possible values of $E_{X}$ is also enormously large. Therefore, let us regard $E_{X}$, $E_{A}$, $E_{B}$ as variables taking continuous values.
Returning to finding the macrostate, let the macrostate (energy) at thermal equilibrium be $\overline{E} = \overline{E}_{A} + \overline{E}_{B}$. Then this means that differentiating $(1)$ with respect to $E_{A}$ and substituting $E_{A}=\overline{E}_{A}$ yields $0$.
$$ \left. \dfrac{d( \Omega_{A} (E_{A} ) \Omega_{B} (E_{B}) )}{dE_{A}} \right|_{E_{A}=\overline{E}_{A}} = 0 $$
Computing the above expression, by the product rule we get the following.
$$ \Omega_{B} (E_{B}) \left. \dfrac{d \Omega_{A} (E_{A} )}{d E_{A}} \right|_{E_{A}=\overline{E}_{A}} + \Omega_{A} (E_{A}) \left. \dfrac{d \Omega_{B} (E_{B} )}{d E_{B}} {{d E_{B} } \over {d E_{A} }} \right|_{E_{A}=\overline{E}_{A}} = 0 $$
Here, no matter how energy moves between $A$ and $B$, the total energy $E_{X} = E_{A} + E_{B}$ is an unchanging constant, so the following holds.
$$ d E_{A} = - d E_{B} \implies \dfrac{d E_{B}}{d E_{A} } = -1 $$
Substituting this into the equation above yields the following.
$$ \begin{align*} && \Omega_{B} \left. \dfrac{ d \Omega_{A} }{d E_{A}}\right|_{E_{A}=\overline{E}_{A}} - \left. \Omega_{A} \dfrac{ d \Omega_{B} }{d E_{B}}\right|_{E_{B}=\overline{E}_{B}} =& 0 \\ \implies && \dfrac{1}{ \Omega_{A} } \left. \dfrac{ d \Omega_{A} }{d E_{A}}\right|_{E_{A}=\overline{E}_{A}} - \dfrac{1}{\Omega_{B} } \left. \dfrac{ d \Omega_{B} }{d E_{B}} \right|_{E_{B}=\overline{E}_{B}} =& 0 \\ \implies && \dfrac{1}{ \Omega_{A} } \left. \dfrac{ d \Omega_{A} }{d E_{A}} \right|_{E_{A}=\overline{E}_{A}} =& \dfrac{1}{\Omega_{B} } \left. \dfrac{ d \Omega_{B} }{d E_{B}} \right|_{E_{B}=\overline{E}_{B}} \\ \implies && \dfrac{ d \ln \Omega_{A} }{d E_{A}} \left(\overline{E}_{A}\right) =& \dfrac{ d \ln \Omega_{B} }{d E_{B}}\left(\overline{E}_{B}\right) \end{align*} $$
The last line holds by the derivative of the logarithm and the chain rule. Here, the above equation is the condition for thermal equilibrium: looking at the left-hand side, it is a value composed only of the variables of system $A$, and the right-hand side is a value composed only of the variables of system $B$. Since, at thermal equilibrium, expressions written solely in terms of each side’s own state take the same value, it is reasonable to define temperature by this value. Then the temperatures $T_{A}$ and $T_{B}$ of $A$ and $B$ can be defined as follows.
$$ \begin{align*} \dfrac{1}{k_{B} T_{A} } &:= \dfrac{ d \ln \Omega _{A} }{d E_{A}} \left(\overline{E}_{A}\right) \\ \dfrac{1}{k_{B} T_{B} } &:= \dfrac{ d \ln \Omega _{B} }{d E_{B}} \left(\overline{E}_{B}\right) \end{align*} $$
■
