Euclidean Algorithm

Algorithm
The Euclidean algorithm is a method for finding the greatest common divisor (GCD) of two integers $a$ and $b$.

Let $a, b \in \Z$ and $a \ne 0 \lor b \ne 0$.

The steps are:
 * $(1): \quad$ Start with $\left({a, b}\right)$ such that $\left|{a}\right| \ge \left|{b}\right|$. If $b = 0$ then the task is complete and the GCD is $a$.
 * $(2): \quad$ If $b \ne 0$ then you take the remainder $r$ of $\dfrac a b$.
 * $(3): \quad$ Set $a \gets b, b \gets r$ (and thus $\left|{a}\right| \ge \left|{b}\right|$ again).
 * $(4): \quad$ Repeat these steps until $b = 0$.

Thus the GCD of $a$ and $b$ is the value of the variable $a$ after the termination of the algorithm.

Constructing an Integer Combination
Having done this, we are now in a position to find a solution to $\gcd \left\{{a, b}\right\} = x a + y b$ for $x$ and $y$.

By Bézout's Identity it is always possible to find such an $x, y \in \Z$.

Working back through the equations above, we get:

... and so on. The algebra gets messier the further up the tree you go, and is not immediately enlightening.

Thus eventually we arrive at $\gcd \left\{{a, b}\right\} = x a + y b$ where $x$ and $y$ are numbers made up from some algebraic cocktail of the coefficients of the terms involving the remainders from the various applications of the Division Theorem.

Note that $a \mathrel \backslash b \implies \gcd \left\{{a, b}\right\} = a$, from GCD of Integer and Divisor.

Also known as
The Euclidean algorithm is also known as Euclid's algorithm or the Euclidean division algorithm.

Also see

 * Rational Numbers and SFCFs are Equivalent‎ for an application of the Euclidean algorithm in a slightly different context.