[proofplan]
The two sides of the identity arise from computing the degree of a canonical divisor on $C$ in two different ways. On a smooth projective curve $X$ of genus $g$, the canonical divisor satisfies $\deg K_X = 2g - 2$. We construct a specific canonical divisor $K_C$ on $C$ by pulling back a meromorphic differential $\omega \in \Omega_{C'}(\eta)$ along $\phi$. The key local computation: at a point $p \in C$ where $\phi$ has ramification index $e_p$, pullback transforms valuations of differentials by $\operatorname{ord}_p(\phi^* \omega) = e_p \operatorname{ord}_{\phi(p)}(\omega) + (e_p - 1)$. Summing this local identity over all $p$ partitions $\deg \operatorname{div}(\phi^* \omega)$ into a $d$-fold pullback contribution from $\operatorname{div}(\omega)$ on $C'$ and a "ramification correction" $\sum_p (e_p - 1)$. Setting the result equal to $2 g(C) - 2$ yields the formula.
[/proofplan]
[step:Set up the canonical divisors via meromorphic differentials]
For a smooth projective curve $X$ over the algebraically closed field $k$, the space $\Omega_X(\eta)$ of meromorphic differentials at the generic point $\eta$ is a one-dimensional $k(X)$-vector space. For any nonzero $\omega \in \Omega_X(\eta)$, the divisor of zeros and poles
\begin{align*}
\operatorname{div}(\omega) = \sum_{x \in X} \operatorname{ord}_x(\omega) \cdot x
\end{align*}
is a canonical divisor on $X$, and all canonical divisors are linearly equivalent. Applying the [Riemann–Roch Theorem](/theorems/2185) twice — once to $D = 0$ (to obtain $\ell(K_X) = g$ from $\ell(0) - \ell(K_X) = 0 - g + 1$) and once to $D = K_X$ (to obtain $\ell(K_X) - \ell(0) = \deg K_X - g + 1$) — and substituting $\ell(0) = 1$ (the constants), we deduce
\begin{align*}
\deg \operatorname{div}(\omega) = \deg K_X = 2 g(X) - 2.
\end{align*}
Apply this to $X = C'$: pick a nonzero meromorphic differential $\omega \in \Omega_{C'}(\eta)$. Its divisor satisfies $\deg \operatorname{div}(\omega) = 2 g(C') - 2$.
The pullback of differentials along $\phi$ is the $k$-linear map
\begin{align*}
\phi^* : \Omega_{C'}(\eta) &\to \Omega_C(\eta), \\
\omega &\mapsto \phi^* \omega,
\end{align*}
defined locally by: if $\omega = f\, dt$ on a neighbourhood of $q = \phi(p)$ for a function $f$ regular at $q$ and a local uniformiser $t = t_q$ at $q$, then
\begin{align*}
\phi^* \omega = (f \circ \phi)\, d(\phi^* t) = (f \circ \phi)\, d(t \circ \phi).
\end{align*}
Since $\phi$ is nonconstant and $\omega$ is nonzero, $\phi^* \omega \in \Omega_C(\eta)$ is nonzero (the function field map $\phi^* : k(C') \to k(C)$ is injective, hence $\phi^*$ is injective on differentials).
Hence $\operatorname{div}(\phi^* \omega)$ is a canonical divisor on $C$, and by the same theorem,
\begin{align*}
\deg \operatorname{div}(\phi^* \omega) = 2 g(C) - 2.
\end{align*}
The strategy is to compute $\deg \operatorname{div}(\phi^* \omega)$ in a second way — point by point, using a local formula at each $p \in C$ — and equate the two expressions.
[/step]
[step:Compute the local valuation $\operatorname{ord}_p(\phi^* \omega)$ at a point with ramification index $e_p$]
Fix $p \in C$ and let $q = \phi(p) \in C'$. Choose local uniformisers $t = t_q$ at $q$ and $s = t_p$ at $p$, so $\operatorname{ord}_q(t) = 1 = \operatorname{ord}_p(s)$. The pullback satisfies
\begin{align*}
\phi^* t = u \cdot s^{e_p}
\end{align*}
for some unit $u \in \mathcal{O}_{C, p}^\times$, by the definition of $e_p$ as $\operatorname{ord}_p(\phi^* t)$.
Write $\omega = f\, dt$ in a neighbourhood of $q$, where $f \in k(C')^\times$. Then $\operatorname{ord}_q(\omega) = \operatorname{ord}_q(f)$, since $dt$ has $\operatorname{ord}_q = 0$ (this is the convention: $dt$ is a generator of $\Omega_{C',q}$ at the smooth point $q$, where $t$ is a uniformiser).
Pulling back:
\begin{align*}
\phi^* \omega = (\phi^* f) \cdot d(\phi^* t) = (\phi^* f) \cdot d(u s^{e_p}).
\end{align*}
We expand the differential using the Leibniz and chain rules in $\Omega_{\mathcal{O}_{C,p} / k}$:
\begin{align*}
d(u s^{e_p}) = (du) s^{e_p} + u \cdot d(s^{e_p}) = s^{e_p}\, du + u \cdot e_p s^{e_p - 1}\, ds.
\end{align*}
Since $u \in \mathcal{O}_{C,p}^\times$ is a unit, $du \in \Omega_{\mathcal{O}_{C,p}/k}$ is a regular differential at $p$, so $\operatorname{ord}_p(du) \geq 0$. Hence $\operatorname{ord}_p(s^{e_p}\, du) \geq e_p$.
The second term has $\operatorname{ord}_p(u \cdot e_p s^{e_p - 1}\, ds) = \operatorname{ord}_p(u) + \operatorname{ord}_p(e_p) + (e_p - 1) + \operatorname{ord}_p(ds) = 0 + 0 + (e_p - 1) + 0 = e_p - 1$, using $\operatorname{ord}_p(u) = 0$ (unit), $\operatorname{ord}_p(e_p) = 0$ (the integer $e_p \in k$ is nonzero by the tame ramification hypothesis $\gcd(e_p, \mathrm{char}\, k) = 1$), and $\operatorname{ord}_p(ds) = 0$ (since $s$ is a local uniformiser at $p$, $ds$ generates $\Omega_{\mathcal{O}_{C,p}/k}$ as a free module of rank $1$).
Comparing valuations: the second term has valuation exactly $e_p - 1$, the first term has valuation at least $e_p > e_p - 1$. The valuation of a sum is at least the minimum, with equality when only one term achieves the minimum. Hence
\begin{align*}
\operatorname{ord}_p(d(\phi^* t)) = e_p - 1.
\end{align*}
Combining,
\begin{align*}
\operatorname{ord}_p(\phi^* \omega) = \operatorname{ord}_p(\phi^* f) + \operatorname{ord}_p(d(\phi^* t)) = \operatorname{ord}_p(\phi^* f) + (e_p - 1).
\end{align*}
The first term computes by the formula for valuations under pullback: for $f \in k(C')^\times$,
\begin{align*}
\operatorname{ord}_p(\phi^* f) = e_p \cdot \operatorname{ord}_q(f) = e_p \cdot \operatorname{ord}_q(\omega).
\end{align*}
This identity follows directly from $\phi^* t = u s^{e_p}$ and writing $f = c\, t^{m}$ at the leading order with $m = \operatorname{ord}_q(f)$ and $c \in \mathcal{O}_{C',q}^\times$: then $\phi^* f = (c \circ \phi) (\phi^* t)^m = (c \circ \phi) u^m s^{e_p m}$, so $\operatorname{ord}_p(\phi^* f) = e_p m$.
Conclusion: at every $p \in C$,
\begin{align*}
\operatorname{ord}_p(\phi^* \omega) = e_p \cdot \operatorname{ord}_q(\omega) + (e_p - 1), \qquad q = \phi(p).
\end{align*}
[guided]
The local computation has two components: how the function part $f$ pulls back, and how the differential part $dt$ pulls back. Each contributes its own term to $\operatorname{ord}_p(\phi^* \omega)$.
\textbf{(a) Pullback of the function $f$.} The local model of a tamely ramified morphism is $\phi^* t = u s^{e_p}$. From this,
\begin{align*}
\phi^* f = f \circ \phi = (\text{leading term: } c \cdot t^m) \circ \phi = c \cdot (u s^{e_p})^m = c \cdot u^m \cdot s^{e_p m},
\end{align*}
where $m = \operatorname{ord}_q(f)$ and $c$ is a unit at $q$. The valuation at $p$ of this is $0 + 0 + e_p m = e_p \operatorname{ord}_q(f)$. The intuition: a uniformiser $t$ at $q$ has order $e_p$ when pulled back to $p$, so any $f$ with order $m$ in $t$ has order $e_p m$ in $s$.
\textbf{(b) Pullback of the differential $dt$.} This is where the ramification correction $e_p - 1$ enters. By the chain rule,
\begin{align*}
d(\phi^* t) = d(u s^{e_p}) = e_p u s^{e_p - 1}\, ds + s^{e_p}\, du.
\end{align*}
The first term has valuation $e_p - 1$ (the constant $e_p$ is a unit by the tame ramification hypothesis $\gcd(e_p, \mathrm{char}\, k) = 1$ — this is precisely where tameness is consumed; in wild ramification, $e_p$ would be divisible by the characteristic and the term $e_p u s^{e_p - 1} ds$ would vanish identically, requiring a different leading-order analysis). The second term has valuation $\geq e_p$. The first term wins, so
\begin{align*}
\operatorname{ord}_p(d(\phi^* t)) = e_p - 1.
\end{align*}
Note: when $e_p = 1$ (unramified), this gives $\operatorname{ord}_p(d(\phi^* t)) = 0$, as expected — a local isomorphism preserves valuations of differentials.
\textbf{Combining.} The differential $\omega = f \, dt$ pulls back to $\phi^* \omega = (\phi^* f) \cdot d(\phi^* t)$, so
\begin{align*}
\operatorname{ord}_p(\phi^* \omega) = \operatorname{ord}_p(\phi^* f) + \operatorname{ord}_p(d(\phi^* t)) = e_p \operatorname{ord}_q(f) + (e_p - 1) = e_p \operatorname{ord}_q(\omega) + (e_p - 1).
\end{align*}
The first term scales by $e_p$ — this is the linear "expansion factor" of pullback on valuations. The second term is a $+(e_p - 1)$ correction that detects ramification: it is positive precisely when $e_p > 1$, i.e., at the ramification points of $\phi$. This correction is what distinguishes Riemann–Hurwitz from a naive pullback identity.
[/guided]
[/step]
[step:Sum the local identity over all $p \in C$ to compute $\deg \operatorname{div}(\phi^* \omega)$]
We sum the local identity $\operatorname{ord}_p(\phi^* \omega) = e_p \operatorname{ord}_{\phi(p)}(\omega) + (e_p - 1)$ over all closed points $p \in C$.
First, $e_p = 1$ for all but finitely many $p$: the ramification locus
\begin{align*}
R(\phi) = \{ p \in C : e_p \geq 2 \}
\end{align*}
is a finite set. This follows from the fact that the ramification locus is the support of an effective divisor on $C$ (the "ramification divisor"), or equivalently from the differential $d\phi : T_p C \to T_{\phi(p)} C'$ being an isomorphism off a proper closed subset — a closed subset of a curve is either finite or all of $C$, and "all of $C$" is excluded since $\phi$ is separable (we will use this implicitly via tameness, where $\gcd(e_p, \mathrm{char}\, k) = 1$ for all $p$ rules out wild generic ramification). Hence the sum $\sum_p (e_p - 1)$ has only finitely many nonzero terms, so it is finite.
Now compute:
\begin{align*}
\deg \operatorname{div}(\phi^* \omega) = \sum_{p \in C} \operatorname{ord}_p(\phi^* \omega) = \sum_{p \in C} \bigl[ e_p \operatorname{ord}_{\phi(p)}(\omega) + (e_p - 1) \bigr].
\end{align*}
We split the sum:
\begin{align*}
\sum_{p \in C} e_p \operatorname{ord}_{\phi(p)}(\omega) + \sum_{p \in C}(e_p - 1).
\end{align*}
For the first sum, group the points of $C$ by their image in $C'$: for each $q \in C'$, the points of $C$ above $q$ are the elements of the fibre $\phi^{-1}(q)$, and
\begin{align*}
\sum_{p \in \phi^{-1}(q)} e_p = d
\end{align*}
by [Degree Equals Sum of Ramification Indices](/theorems/2174) (the sum of ramification indices in a fibre equals the degree, valid for finite separable morphisms of smooth projective curves over an algebraically closed field). Hence
\begin{align*}
\sum_{p \in C} e_p \operatorname{ord}_{\phi(p)}(\omega) = \sum_{q \in C'} \operatorname{ord}_q(\omega) \sum_{p \in \phi^{-1}(q)} e_p = \sum_{q \in C'} \operatorname{ord}_q(\omega) \cdot d = d \cdot \deg \operatorname{div}(\omega).
\end{align*}
(The reordering of the double sum is legitimate because only finitely many summands are nonzero: $\operatorname{ord}_q(\omega) \neq 0$ for finitely many $q$, and each fibre $\phi^{-1}(q)$ is finite.)
By Step 1, $\deg \operatorname{div}(\omega) = 2 g(C') - 2$. Hence
\begin{align*}
\sum_{p \in C} e_p \operatorname{ord}_{\phi(p)}(\omega) = d \bigl(2 g(C') - 2\bigr).
\end{align*}
Substituting back:
\begin{align*}
\deg \operatorname{div}(\phi^* \omega) = d \bigl(2 g(C') - 2\bigr) + \sum_{p \in C}(e_p - 1).
\end{align*}
[/step]
[step:Equate the two expressions for $\deg \operatorname{div}(\phi^* \omega)$ to obtain the Riemann–Hurwitz formula]
By Step 1, $\operatorname{div}(\phi^* \omega)$ is a canonical divisor on $C$, so
\begin{align*}
\deg \operatorname{div}(\phi^* \omega) = 2 g(C) - 2.
\end{align*}
By Step 3,
\begin{align*}
\deg \operatorname{div}(\phi^* \omega) = d \bigl(2 g(C') - 2\bigr) + \sum_{p \in C}(e_p - 1).
\end{align*}
Equating:
\begin{align*}
2 g(C) - 2 = d \bigl(2 g(C') - 2\bigr) + \sum_{p \in C} (e_p - 1).
\end{align*}
This is the Riemann–Hurwitz formula.
[/step]