Let \(g = \operatorname{gcd}(a,b)\text{.}\) We find \(x\) and \(y\) recursively using back-substitution in the Euclidean algorithm. We start by rewriting \(x_0 = 1\) and \(y_0 = -q_0\) so that
\begin{align*}
r_0 \amp = a + (-q_0)b = x_0a + y_0b\\
r_1 \amp = b + (-q_1)r_0 \\
\amp = b + (-q_1)(x_0a + y_0)b\\
\amp = (-q_1x_0)a + (1 - q_0y_0)b.
\end{align*}
Take \(x_1 = -q_1x_0\) and \(y_1 = 1 - q_0y_0\text{,}\) so that
\begin{equation*}
r_1 = x_1 a + y_1 b.
\end{equation*}
Now assume that for some \(k > 2\) we have written \(r_i = x_ia + y_ib\) for each \(0 \leq i \lt k\text{.}\) From the Euclidean Algorithm we have
\begin{align*}
r_{k-2} = q_kr_{k-1} + r_k
\amp \iff r_k = r_{k-2} - q_kr_{k-1}\\
\amp \iff r_k = (x_{k-2}a + y_{k-2}b) + (-q_k)(x_{k-1}a + y_{k-1}b)\\
\amp \iff r_k = (x_{k-2} - q_kx_{k-1})a + (y_{k-2} - q_kq_{k-1})b.
\end{align*}
so if \(x_k = x_{k-2} - q_kx_{k-1}\) and \(y_k = y_{k-2} - q_kq_{k-1}\text{,}\) then
\begin{equation*}
r_k = x_ka + y_kb.
\end{equation*}
Since \(r_n = g\) is the greatest common divisor of \(a\) and \(b\text{,}\) it follows that there exist \(x,y \in \Z\) such that \(r_n = ax + by\) by induction.