[guided]We want to translate the global condition "$df = 0$" into a structural property of $f$. The natural intermediate is being **locally constant**, since vanishing differential is itself a local condition.
Assume $df = 0$. Pick $p \in M$. By the definition of a smooth manifold, $p$ lies in some chart, and we may shrink the chart to a chart $(U,\varphi)$ with $\varphi(U) = B(\varphi(p),r)$ for some $r > 0$ — this is possible because open balls form a basis for the topology of $\mathbb{R}^n$, so we can replace $U$ by $\varphi^{-1}(B(\varphi(p),r))$ for $r$ small enough. Quantifying the shrinking is essential: we need the image $\varphi(U)$ to be **convex** so that straight-line paths stay inside it.
Set $\tilde f := f\circ\varphi^{-1}:\varphi(U)\to\mathbb{R}$, which is smooth. The hypothesis $df = 0$ pulls back to $\partial_{x_i}\tilde f \equiv 0$ on $\varphi(U)$ for every $i$. (This is the coordinate expression of $df$: $df|_U = \sum_i (\partial_{x_i}\tilde f)\circ\varphi\, dx_i$, and a $1$-form vanishes iff all its coefficients vanish.)
To deduce that $\tilde f$ is constant on the ball $\varphi(U) = B(\varphi(p),r)$, we use that the ball is path-connected by straight segments. For $y \in \varphi(U)$, the straight line $\gamma:[0,1]\to\varphi(U)$, $\gamma(t) = (1-t)\varphi(p) + t\, y$, stays in $\varphi(U)$ by convexity. The composite $g := \tilde f\circ\gamma$ is smooth on $[0,1]$ with derivative
\begin{align*}
g'(t) \;=\; \sum_{i=1}^n (\partial_{x_i}\tilde f)(\gamma(t))\,(y_i - \varphi(p)_i) \;=\; 0
\end{align*}
by the chain rule and the vanishing of the partials. The [Fundamental Theorem of Calculus](/theorems/632) (applied to $g$ on $[0,1]$, valid because $g'$ is continuous on $[0,1]$) gives
\begin{align*}
\tilde f(y) - \tilde f(\varphi(p)) \;=\; g(1) - g(0) \;=\; \int_0^1 g'(t)\,d\mathcal{L}^1(t) \;=\; 0,
\end{align*}
so $\tilde f \equiv \tilde f(\varphi(p))$ on $\varphi(U)$. Pulling back to $M$, $f$ is constant on $U$. As $p$ was arbitrary, $f$ is locally constant.
The converse is automatic: if $f$ is constant on a neighbourhood $U$ of $p$, then in any chart its partial derivatives vanish at $p$, so $df_p = 0$; this holds at every $p$, so $df \equiv 0$ on $M$.
Note how the local Euclidean structure is consumed twice here: once to talk about partial derivatives, and once to invoke convexity of small balls so the FTC argument runs.[/guided]