Skip to content

Alerts Center

New quiz added: Multiplication Tables — try it now

Fractions lesson updated with new practice worksheets

This month's resource pack is now live

View All Alerts

Messages

Tip: Create a free account to save your quiz progress

New here? Check out our Getting Started guide

New Sudoku puzzles added this week

View All Messages

Factors, Multiples & Primes

The Euclidean Algorithm – The Fastest Way to Find the GCF

The Euclidean Algorithm is a method for finding the GCF of two numbers that was described by the Greek mathematician Euclid around 300 BC. It remains one of the most efficient algorithms in all of mathematics, even for very large numbers.

Historians of mathematics often call this the oldest nontrivial algorithm still in everyday use — the Greeks themselves called the underlying idea anthyphairesis (“reciprocal subtraction”), and it appears in Book VII of Euclid’s Elements essentially unchanged from the version taught today. Donald Knuth, one of the founders of modern computer science, went so far as to call it “the granddaddy of all algorithms” in his classic textbook The Art of Computer Programming, because it is also one of the earliest known examples of a precisely specified, guaranteed-to-terminate step-by-step procedure — the very definition of what an algorithm is.

The Core Idea

GCF(a, b) = GCF(b, a mod b), where “mod” means the remainder when a is divided by b. Repeat until the remainder is 0. The GCF is the last non-zero remainder.

Step by Step: Applying the Algorithm

  1. Divide the larger number by the smaller number, and find the remainder.
  2. Replace the larger number with the smaller number, and replace the smaller number with that remainder.
  3. Repeat step 1 on the new pair.
  4. Stop as soon as the remainder is 0. The GCF is whatever the smaller number was on that final step — in other words, the last non-zero remainder you calculated.
Compare this to the ladder method: the ladder method (covered on the Methods for Finding the GCF page) divides both numbers by one small prime at a time, rung by rung. The Euclidean Algorithm skips straight to dividing by whatever the largest number happens to be at each step — no primes required at all — which is exactly why it finishes in far fewer steps, even on huge numbers.

Step-by-Step Example 1

GCF(48, 18)
StepDivisionRemainder
148 ÷ 18 = 2 remainder 1212
218 ÷ 12 = 1 remainder 66
312 ÷ 6 = 2 remainder 00 — stop

GCF(48,18) = 6

Step-by-Step Example 2

GCF(252, 105)
StepDivisionRemainder
1252 ÷ 105 = 2 r 4242
2105 ÷ 42 = 2 r 2121
342 ÷ 21 = 2 r 00 — stop

GCF(252,105) = 21

More Examples, Including Two Special Cases

Special case — one number divides the other exactly: GCF(45, 15)
StepDivisionRemainder
145 ÷ 15 = 3 remainder 00 — stop

GCF(45,15) = 15

When the smaller number already divides the larger one exactly, the algorithm finishes in a single step — the smaller number itself is the GCF.

Special case — coprime numbers: GCF(17, 5)
StepDivisionRemainder
117 ÷ 5 = 3 remainder 22
25 ÷ 2 = 2 remainder 11
32 ÷ 1 = 2 remainder 00 — stop

GCF(17,5) = 1

A GCF of 1 means the two numbers are coprime — they share no common factor at all beyond 1. The algorithm handles this exactly the same way as any other case; it just happens to land on 1 as the final non-zero remainder.

Large numbers — where the speed really shows: GCF(1071, 462)
StepDivisionRemainder
11071 ÷ 462 = 2 remainder 147147
2462 ÷ 147 = 3 remainder 2121
3147 ÷ 21 = 7 remainder 00 — stop

GCF(1071,462) = 21

Just three divisions solved a problem that would need listing dozens of factors of 1071 and 462, or fully factoring both into primes, to solve any other way.

Why It Works

If d divides both a and b, it also divides their difference a − b, and any remainder when a is divided by b. So the set of common divisors of (a, b) is identical to that of (b, remainder). We keep reducing until one number is 0, leaving the GCF.

Seeing it directly: take a = 48, b = 18. Every common divisor of 48 and 18 — namely 1, 2, 3, and 6 — also divides the remainder when 48 is divided by 18, which is 12. And sure enough, 1, 2, 3, and 6 all divide 12 as well. Nothing was lost by replacing (48, 18) with (18, 12): the exact same set of common divisors survives at every single step, all the way down to the final pair, which is why the last non-zero remainder is guaranteed to be the true GCF.

How Fast Is It, Really?

The Euclidean Algorithm isn’t just fast in practice — how fast it is has actually been proven mathematically. A 19th-century result known as Lamé’s theorem shows that the number of division steps needed is never more than about five times the number of digits in the smaller number. A pair of 100-digit numbers, however enormous, will always finish in well under 500 steps — which is instant for a computer, and entirely manageable by hand.

The numbers that force the most steps for their size, it turns out, are consecutive Fibonacci numbers — a beautiful, unexpected link between two completely different areas of mathematics.

The slowest possible case for its size: GCF(13, 8)
StepDivisionRemainder
113 ÷ 8 = 1 remainder 55
28 ÷ 5 = 1 remainder 33
35 ÷ 3 = 1 remainder 22
43 ÷ 2 = 1 remainder 11
52 ÷ 1 = 2 remainder 00 — stop

GCF(13,8) = 1 — but it took 5 whole steps to get there, far more than the earlier examples used on numbers of similar or even larger size. 13 and 8 are consecutive Fibonacci numbers (…3, 5, 8, 13, 21…), and every consecutive Fibonacci pair behaves this way — each step’s quotient is always exactly 1, which is precisely what makes the algorithm take as many steps as possible.

Key Takeaways

  • Divide the larger by the smaller; take the remainder.
  • Replace the larger with the smaller and the smaller with the remainder.
  • Repeat until the remainder is 0; the GCF is the last non-zero remainder.
  • If the smaller number divides the larger exactly, the algorithm finishes in one step.
  • A final GCF of 1 means the two numbers are coprime.
  • Far faster than listing factors for large numbers — Lamé’s theorem guarantees it never takes more than about five times the digit-count of the smaller number.
  • Once GCF is found, use LCM = (a × b) ÷ GCF.

Practice: Euclidean Algorithm

Find the GCF Step by Step