[proofplan]
We compare two powers of $g$ by translating the equality $g^a=g^b$ into the condition that the single power $g^{a-b}$ is the identity. Thus the proof reduces to identifying which integers $k$ satisfy $g^k=e$. In infinite order, only $k=0$ works; in finite order $n$, the [division algorithm](/theorems/725) and the minimality of $n$ show that exactly the multiples of $n$ work.
[/proofplan]
[step:Reduce equality of two powers to a power equal to the identity]
Let $e$ denote the identity element of $G$. We use the standard integer-power convention in a group: for $m \in \mathbb{Z}$, $g^m$ is defined by positive powers, $g^0=e$, and $g^{-m}=(g^m)^{-1}$ when $m>0$.
For $a,b \in \mathbb{Z}$, the integer exponent laws give
\begin{align*} g^a=g^b \iff g^a g^{-b}=e \iff g^{a-b}=e. \end{align*}
Conversely, if $g^{a-b}=e$, then
\begin{align*} g^a=g^{a-b+b}=g^{a-b}g^b=eg^b=g^b. \end{align*}
Therefore the theorem is equivalent to determining the set of integers $k$ for which $g^k=e$.
[guided]
The purpose of this reduction is to turn an equality between two possibly different powers into a statement about one exponent. Let $e$ be the identity element of $G$. Integer powers are understood as follows: $g^0=e$, positive powers are repeated products of $g$, and for $m>0$ one defines $g^{-m}=(g^m)^{-1}$.
Suppose first that $g^a=g^b$. Multiplying both sides on the right by $g^{-b}$ gives
\begin{align*}
g^a g^{-b}=g^b g^{-b}=e.
\end{align*}
By the integer exponent law $g^r g^s=g^{r+s}$ for $r,s \in \mathbb{Z}$, the left-hand side is $g^{a-b}$. Hence
\begin{align*}
g^{a-b}=e.
\end{align*}
Conversely, suppose $g^{a-b}=e$. Using the same integer exponent law,
\begin{align*}
g^a=g^{a-b+b}=g^{a-b}g^b=eg^b=g^b.
\end{align*}
Thus
\begin{align*}
g^a=g^b \iff g^{a-b}=e.
\end{align*}
So the remaining task is to characterize all integers $k$ satisfying $g^k=e$.
[/guided]
[/step]
[step:Show that infinite order forces the kernel of powers to be zero]
Assume $\operatorname{ord}(g)=\infty$. We claim that for $k \in \mathbb{Z}$,
\begin{align*}
g^k=e \iff k=0.
\end{align*}
The implication $k=0 \implies g^k=e$ follows from the definition of $g^0$. Conversely, suppose $g^k=e$. If $k>0$, then a positive power of $g$ equals $e$, contradicting $\operatorname{ord}(g)=\infty$. If $k<0$, then $-k>0$ and
\begin{align*}
g^{-k}=(g^k)^{-1}=e^{-1}=e,
\end{align*}
again contradicting $\operatorname{ord}(g)=\infty$. Hence $k$ is neither positive nor negative, so $k=0$.
Applying this with $k=a-b$, we obtain
\begin{align*}
g^a=g^b \iff g^{a-b}=e \iff a-b=0 \iff a=b.
\end{align*}
This proves the infinite-order case.
[/step]
[step:Characterize the powers equal to the identity in finite order]
Assume $\operatorname{ord}(g)=n$ with $n \in \mathbb{N}$. We claim that for $k \in \mathbb{Z}$,
\begin{align*}
g^k=e \iff n \mid k.
\end{align*}
If $n \mid k$, then there exists $q \in \mathbb{Z}$ such that $k=qn$. Since $g^n=e$, the integer exponent laws give
\begin{align*}
g^k=g^{qn}=(g^n)^q=e^q=e.
\end{align*}
Conversely, suppose $g^k=e$. By the division algorithm, there exist unique integers $q,r \in \mathbb{Z}$ with $0 \le r < n$ such that
\begin{align*}
k=qn+r.
\end{align*}
Then
\begin{align*}
e=g^k=g^{qn+r}=(g^n)^q g^r=e^q g^r=g^r.
\end{align*}
Since $n=\operatorname{ord}(g)$ is the least positive integer satisfying $g^n=e$, no integer $r$ with $0<r<n$ can satisfy $g^r=e$. Because $0 \le r<n$ and $g^r=e$, we must have $r=0$. Therefore $k=qn$, so $n \mid k$.
[/step]
[step:Apply the finite-order characterization to the exponent difference]
Assume $\operatorname{ord}(g)=n$ with $n \in \mathbb{N}$. From the first step,
\begin{align*}
g^a=g^b \iff g^{a-b}=e.
\end{align*}
By the finite-order characterization just proved, applied to the integer $k=a-b$,
\begin{align*}
g^{a-b}=e \iff n \mid (a-b).
\end{align*}
Combining the two equivalences gives
\begin{align*}
g^a=g^b \iff n \mid (a-b).
\end{align*}
This proves the finite-order case and completes the proof.
[/step]