[proofplan]
We prove by set induction, using Foundation, that every set is contained in some level $V_\alpha$ of the cumulative hierarchy. Given a set $x$, the inductive hypothesis gives ranks for all elements $y \in x$; Replacement collects these ranks into a set of ordinals. Taking the supremum of their successors produces one ordinal level containing every element of $x$, and the well-ordering of the ordinals then gives the least such level, which is $\operatorname{rank}(x)$.
[/proofplan]
[step:Use Foundation to reduce rank existence for $x$ to rank existence for its elements]
Let $P(x)$ be the assertion that there exists an ordinal $\alpha$ such that $x \subseteq V_\alpha$. We prove $P(x)$ for every set $x$ by set induction, which is the induction principle obtained from the Axiom of Foundation.
Fix a set $x$, and assume the induction hypothesis that $P(y)$ holds for every $y \in x$. Thus, for each $y \in x$, there exists an ordinal $\beta$ such that $y \subseteq V_\beta$.
[guided]
Define the property $P$ on sets by declaring that $P(x)$ means
\begin{align*}
\exists \alpha \in \operatorname{Ord}\text{ such that }x \subseteq V_\alpha.
\end{align*}
The Axiom of Foundation implies set induction: to prove $P(x)$ for all sets $x$, it is enough to prove that whenever $P(y)$ holds for every element $y \in x$, then $P(x)$ holds.
So fix a set $x$ and assume the induction hypothesis:
\begin{align*}
\forall y \in x,\ \exists \beta \in \operatorname{Ord}\text{ such that }y \subseteq V_\beta.
\end{align*}
This is exactly where Foundation enters the proof: it lets us assume rank-boundedness for all elements of $x$ before proving rank-boundedness for $x$ itself.
[/guided]
[/step]
[step:Define the least bounding level for each element of $x$]
For each $y \in x$, define
\begin{align*}
\rho(y)=\min\{\beta \in \operatorname{Ord}: y \subseteq V_\beta\}.
\end{align*}
This is well-defined because the induction hypothesis makes the displayed class nonempty, and the ordinals are well-ordered. Thus $\rho(y)$ is an ordinal and $y \subseteq V_{\rho(y)}$ for every $y \in x$.
[guided]
For each element $y \in x$, define the class $A_y$ by
\begin{align*}
A_y:=\{\beta \in \operatorname{Ord}: y \subseteq V_\beta\}.
\end{align*}
The induction hypothesis says exactly that $A_y$ is nonempty. Since $A_y$ is a nonempty class of ordinals, the well-ordering of the ordinals gives a unique least member. Define
\begin{align*}
\rho(y):=\min A_y.
\end{align*}
Thus $\rho(y)$ is an ordinal, $y \subseteq V_{\rho(y)}$, and no smaller ordinal has this property.
The uniqueness of this least ordinal matters because Replacement applies to functional assignments. We are not choosing arbitrary witnesses; we have defined a unique ordinal $\rho(y)$ for each $y \in x$.
[/guided]
[/step]
[step:Use Replacement to collect the element ranks into a set of ordinals]
By the Axiom Schema of Replacement applied to the functional formula defining $\rho(y)$, the collection
\begin{align*}
R_x:=\{\rho(y): y \in x\}
\end{align*}
is a set. Since each $\rho(y)$ is an ordinal, $R_x$ is a set of ordinals.
[guided]
The formula “$\gamma=\rho(y)$” defines a unique ordinal $\gamma$ for each $y \in x$. Therefore Replacement applies and produces the image set
\begin{align*}
R_x:=\{\rho(y): y \in x\}.
\end{align*}
This is the exact point where Replacement enters the proof. Without Replacement, we would know that every element $y \in x$ has some least bounding ordinal, but we would not be entitled to collect all those ordinals into a single set whose supremum can be taken.
[/guided]
[/step]
[step:Take the supremum of successor ranks to bound all elements of $x$]
Define
\begin{align*}
\alpha:=\sup\{\rho(y)+1: y \in x\}.
\end{align*}
Since $R_x$ is a set of ordinals, the set $\{\rho(y)+1:y\in x\}$ is also a set of ordinals, and its supremum $\alpha$ is an ordinal.
For every $y \in x$, we have $\rho(y)+1 \leq \alpha$. Since $y \subseteq V_{\rho(y)}$, the definition of the cumulative hierarchy gives $y \in V_{\rho(y)+1}$. By monotonicity of the hierarchy, $V_{\rho(y)+1} \subseteq V_\alpha$, hence $y \in V_\alpha$. Therefore $x \subseteq V_\alpha$.
[guided]
Now we need one ordinal level that contains every element of $x$. For each $y \in x$, we know
\begin{align*}
y \subseteq V_{\rho(y)}.
\end{align*}
By the successor-stage definition of the cumulative hierarchy,
\begin{align*}
V_{\rho(y)+1}=\mathcal{P}(V_{\rho(y)}),
\end{align*}
so $y \subseteq V_{\rho(y)}$ implies
\begin{align*}
y \in V_{\rho(y)+1}.
\end{align*}
Because Replacement gave us the set of ordinals $R_x=\{\rho(y):y\in x\}$, we may form the set of successor ordinals
\begin{align*}
S_x:=\{\rho(y)+1:y\in x\}.
\end{align*}
Define
\begin{align*}
\alpha:=\sup S_x.
\end{align*}
Then $\alpha$ is an ordinal and $\rho(y)+1\leq \alpha$ for every $y\in x$. The cumulative hierarchy is monotone in the ordinal index, so
\begin{align*}
V_{\rho(y)+1}\subseteq V_\alpha.
\end{align*}
Hence each $y\in x$ belongs to $V_\alpha$. Therefore
\begin{align*}
x\subseteq V_\alpha.
\end{align*}
This proves the induction step.
[/guided]
[/step]
[step:Extract the least bounding ordinal and define the rank]
By set induction, for every set $x$ there exists an ordinal $\alpha_0$ such that $x \subseteq V_{\alpha_0}$. Define the class $B_x$ by
\begin{align*}
B_x:=\{\alpha \in \operatorname{Ord}: x \subseteq V_\alpha\}.
\end{align*}
Then $B_x$ is nonempty because $\alpha_0 \in B_x$. To justify taking the least element of this class, use Separation on the set $\alpha_0+1$ to form
\begin{align*}
C_x:=\{\alpha \in \alpha_0+1: x \subseteq V_\alpha\}.
\end{align*}
The set $C_x$ is a nonempty set of ordinals, so it has a least element $\delta$. Since $C_x \subseteq B_x$ and every element of $B_x$ either lies in $\alpha_0+1$ or is at least $\alpha_0+1$, the ordinal $\delta$ is also the least element of $B_x$. Define
\begin{align*}
\operatorname{rank}(x):=\delta=\min B_x.
\end{align*}
Thus $\operatorname{rank}(x)$ is a well-defined ordinal and satisfies
\begin{align*}
x \subseteq V_{\operatorname{rank}(x)}.
\end{align*}
Uniqueness follows from uniqueness of the least element in a well-ordered set of ordinals. Therefore every set has a rank.
[guided]
By the induction step already proved, for every set $x$ there exists an ordinal $\alpha_0$ such that
\begin{align*}
x \subseteq V_{\alpha_0}.
\end{align*}
Define the class $B_x$ of all ordinal bounds for $x$ by
\begin{align*}
B_x:=\{\alpha \in \operatorname{Ord}: x \subseteq V_\alpha\}.
\end{align*}
This class is nonempty because $\alpha_0 \in B_x$.
We now justify the class-minimum step using only set-level well-ordering. Since $\alpha_0$ is an ordinal, $\alpha_0+1$ is a set. By Separation applied inside the set $\alpha_0+1$, the collection
\begin{align*}
C_x:=\{\alpha \in \alpha_0+1: x \subseteq V_\alpha\}
\end{align*}
is a set. It is nonempty because $\alpha_0 \in C_x$. Since $C_x$ is a nonempty set of ordinals, the well-ordering of ordinals gives a unique least element; call it $\delta$.
The ordinal $\delta$ is not merely least in $C_x$; it is least in the whole class $B_x$. Indeed, let $\beta \in B_x$. If $\beta \in \alpha_0+1$, then $\beta \in C_x$, so $\delta \leq \beta$ by the definition of $\delta$. If $\beta \notin \alpha_0+1$, then $\alpha_0 < \beta$, while $\delta \leq \alpha_0$ because $\delta \in C_x \subseteq \alpha_0+1$; hence again $\delta \leq \beta$. Therefore $\delta$ is the least member of $B_x$.
Define
\begin{align*}
\operatorname{rank}(x):=\delta=\min B_x.
\end{align*}
Then $\operatorname{rank}(x)$ is an ordinal and, because it belongs to $B_x$, it satisfies
\begin{align*}
x \subseteq V_{\operatorname{rank}(x)}.
\end{align*}
The uniqueness of $\operatorname{rank}(x)$ follows from uniqueness of the least element of the set $C_x$, equivalently from antisymmetry of the ordinal order. This completes the proof that every set has a rank.
[/guided]
[/step]