In grade 6 you found the greatest common factor by listing factors. That is fine for $12$ and $18$, hopeless for $2431$ and $1001$, and impossible for numbers with hundreds of digits, which cryptography uses every day. Euclid's algorithm, more than 2,000 years old, finds the gcd with a handful of divisions and no factoring at all.
Definition. For integers $a$ and $b$, not both $0$, the greatest common divisor $\gcd(a, b)$ is the largest integer that divides both. Two numbers with $\gcd(a, b) = 1$ are called coprime (or relatively prime).
Why it works
The algorithm. Divide $a$ by $b$ with the division algorithm, then replace $(a, b)$ by $(b, r)$ and repeat. The remainders get strictly smaller and never go below $0$, so eventually one is $0$. Since $\gcd(g, 0) = g$, the last nonzero remainder is the gcd.
Worked example: A first run
- $252 = 198 \cdot 1 + 54$
- $198 = 54 \cdot 3 + 36$
- $54 = 36 \cdot 1 + 18$
- $36 = 18 \cdot 2 + 0$. The remainder is $0$, so stop.
- The last nonzero remainder is $18$. Check: $252 = 18 \cdot 14$ and $198 = 18 \cdot 11$.
Answer: $\gcd(252, 198) = 18$.
Worked example: Bigger numbers, few steps
- $2431 = 1001 \cdot 2 + 429$
- $1001 = 429 \cdot 2 + 143$
- $429 = 143 \cdot 3 + 0$
- The gcd is $143$. (Indeed $2431 = 11 \cdot 13 \cdot 17$ and $1001 = 7 \cdot 11 \cdot 13$, but the algorithm never needed those factorizations.)
Answer: $\gcd(2431, 1001) = 143$.
Common mistake
Two small conventions make the algorithm work for every input. Signs do not matter, so $\gcd(-252, 198) = \gcd(252, 198)$. And $\gcd(a, 0) = |a|$ for $a \neq 0$, since every integer divides $0$. If you start with the smaller number first, the first division simply swaps them: $198 = 252 \cdot 0 + 198$.
Key idea