[proofplan]
We consider the action of $G$ on itself by conjugation. This action partitions $G$ into disjoint conjugacy classes. The conjugacy class of an element $x$ is the singleton $\{x\}$ if and only if $x \in Z(G)$, so the centre accounts for all orbits of size $1$. The remaining orbits have size greater than $1$, and by the [Orbit-Stabiliser Theorem](/theorems/???), each such orbit has size $[G : C_G(g_i)]$. Summing over all orbits yields the class equation.
[/proofplan]
[step:Partition $G$ into conjugacy classes under the conjugation action]
Define the action $G \curvearrowright G$ by conjugation: the action map $G \times G \to G$ sends $(g, x) \mapsto g x g^{-1}$. This is a well-defined group action since $e \cdot x = e x e^{-1} = x$ for all $x \in G$, and $(gh) \cdot x = (gh)x(gh)^{-1} = g(hxh^{-1})g^{-1} = g \cdot (h \cdot x)$ for all $g, h, x \in G$.
The orbits of this action are the conjugacy classes of $G$. For each $x \in G$, the conjugacy class of $x$ is $\operatorname{Cl}(x) = \{gxg^{-1} : g \in G\}$. Since orbits of a group action partition the underlying set, $G$ is the disjoint union of its distinct conjugacy classes. Let $\operatorname{Cl}(x_1), \ldots, \operatorname{Cl}(x_s)$ denote these distinct conjugacy classes. Then
\begin{align*}
|G| = \sum_{j=1}^{s} |\operatorname{Cl}(x_j)|.
\end{align*}
[guided]
Every group action partitions the set being acted on into disjoint orbits. Here the set is $G$ itself, and the action is conjugation: $(g, x) \mapsto gxg^{-1}$.
We first verify this is indeed a group action. The identity axiom holds: $e \cdot x = exe^{-1} = x$. The compatibility axiom holds: $(gh) \cdot x = (gh)x(gh)^{-1} = g(hxh^{-1})g^{-1} = g \cdot (h \cdot x)$, where we used $(gh)^{-1} = h^{-1}g^{-1}$ and associativity in $G$.
The orbit of $x \in G$ under this action is the conjugacy class $\operatorname{Cl}(x) = \{gxg^{-1} : g \in G\}$. Since orbits of any group action on a set form a partition of that set (they are equivalence classes of the relation $x \sim y$ iff $y = g \cdot x$ for some $g$), we can write $G$ as the disjoint union of its distinct conjugacy classes $\operatorname{Cl}(x_1), \ldots, \operatorname{Cl}(x_s)$. Taking cardinalities:
\begin{align*}
|G| = \sum_{j=1}^{s} |\operatorname{Cl}(x_j)|.
\end{align*}
This is the starting point: we have expressed $|G|$ as a sum over orbit sizes. The next step is to identify which orbits have size $1$ and which have size greater than $1$.
[/guided]
[/step]
[step:Identify the orbits of size $1$ as exactly the elements of $Z(G)$]
The stabiliser of $x$ under the conjugation action is the centraliser $C_G(x) = \{g \in G : gxg^{-1} = x\} = \{g \in G : gx = xg\}$. By the [Orbit-Stabiliser Theorem](/theorems/???), $|\operatorname{Cl}(x)| = [G : C_G(x)]$ for each $x \in G$. In particular, $|\operatorname{Cl}(x)| = 1$ if and only if $C_G(x) = G$, which holds if and only if $gx = xg$ for all $g \in G$, i.e., $x \in Z(G)$.
Therefore, the conjugacy classes of size $1$ are precisely the singletons $\{z\}$ for $z \in Z(G)$, and there are $|Z(G)|$ such classes.
[guided]
We need to determine which conjugacy classes have size exactly $1$. The conjugacy class of $x$ has size $1$ precisely when $gxg^{-1} = x$ for every $g \in G$ -- that is, when $x$ commutes with every element of $G$. This is the defining property of the centre: $x \in Z(G) = \{x \in G : gx = xg \text{ for all } g \in G\}$.
More formally, the stabiliser of $x$ under the conjugation action is
\begin{align*}
G_x = \{g \in G : g \cdot x = x\} = \{g \in G : gxg^{-1} = x\} = C_G(x),
\end{align*}
the centraliser of $x$ in $G$. The [Orbit-Stabiliser Theorem](/theorems/???) states that for a finite group $G$ acting on a set $X$, the orbit of any element $x$ satisfies $|G \cdot x| = [G : G_x]$. Here $G$ is finite by hypothesis, so the theorem applies and gives $|\operatorname{Cl}(x)| = [G : C_G(x)]$.
Now $|\operatorname{Cl}(x)| = 1$ if and only if $[G : C_G(x)] = 1$, which holds if and only if $C_G(x) = G$. But $C_G(x) = G$ means every element of $G$ commutes with $x$, which is precisely the condition $x \in Z(G)$. So the orbits of size $1$ are in bijection with the elements of $Z(G)$, and their total contribution to the sum $\sum |\operatorname{Cl}(x_j)|$ is $|Z(G)|$.
[/guided]
[/step]
[step:Sum over all conjugacy classes to obtain the class equation]
Separate the sum over conjugacy classes into those of size $1$ and those of size greater than $1$. Let $g_1, \ldots, g_r$ be representatives of the conjugacy classes with $|\operatorname{Cl}(g_i)| > 1$. Then
\begin{align*}
|G| &= \sum_{\substack{j=1 \\ |\operatorname{Cl}(x_j)| = 1}}^{s} |\operatorname{Cl}(x_j)| + \sum_{\substack{j=1 \\ |\operatorname{Cl}(x_j)| > 1}}^{s} |\operatorname{Cl}(x_j)| \\
&= |Z(G)| + \sum_{i=1}^{r} |\operatorname{Cl}(g_i)| \\
&= |Z(G)| + \sum_{i=1}^{r} [G : C_G(g_i)],
\end{align*}
where the last equality uses $|\operatorname{Cl}(g_i)| = [G : C_G(g_i)]$ from the [Orbit-Stabiliser Theorem](/theorems/???). This is the class equation.
[guided]
We now assemble the result. The partition of $G$ into conjugacy classes gives
\begin{align*}
|G| = \sum_{j=1}^{s} |\operatorname{Cl}(x_j)|.
\end{align*}
We split this sum into two parts: the orbits of size $1$ (which correspond to elements of $Z(G)$, as shown in the previous step) and the orbits of size greater than $1$. The former contribute one each, for a total of $|Z(G)|$. For the latter, let $g_1, \ldots, g_r$ be representatives. Each such orbit has size $|\operatorname{Cl}(g_i)| = [G : C_G(g_i)]$ by the [Orbit-Stabiliser Theorem](/theorems/???). Therefore
\begin{align*}
|G| &= \underbrace{\sum_{\substack{j : |\operatorname{Cl}(x_j)| = 1}} 1}_{= |Z(G)|} + \sum_{i=1}^{r} [G : C_G(g_i)] \\
&= |Z(G)| + \sum_{i=1}^{r} [G : C_G(g_i)].
\end{align*}
Note that each summand $[G : C_G(g_i)]$ divides $|G|$ by Lagrange's theorem, and $[G : C_G(g_i)] > 1$ since $g_i \notin Z(G)$ (equivalently, $C_G(g_i) \subsetneq G$). This completes the proof of the class equation.
[/guided]
[/step]