Euclid's Algorithm: How to Find the HCF (GCD) Step by Step
EuclidCurve Smart Team · 2026-11-12 · 7 min read
For young mathematicians in the UK, USA, UAE, Singapore and Hong Kong
Euclid's algorithm is more than 2,300 years old and is still one of the fastest ways to find the highest common factor (HCF, also called the GCD) of two numbers. Computers use it every day, including inside the RSA encryption that protects online banking.
Guess first: What is the HCF of 1071 and 462?
- 7
- 21
- 42
1071 = 462 × 2 + 147, then 462 = 147 × 3 + 21, then 147 = 21 × 7 + 0. The HCF is 21. Three divisions, no factor lists.
The steps
Divide the larger number by the smaller one using Euclid's division lemma, a = bq + r. If the remainder is 0, the smaller number is the HCF. Otherwise, replace the pair (a, b) by (b, r) and divide again. The last non-zero remainder is the HCF.
Example: the HCF of 455 and 42. 455 = 42 × 10 + 35, then 42 = 35 × 1 + 7, then 35 = 7 × 5 + 0. The last non-zero remainder is 7, so HCF(455, 42) = 7.
Why it works
If a number divides both a and b, it also divides r = a - bq. And if it divides both b and r, it divides a = bq + r. So the pairs (a, b) and (b, r) have exactly the same common factors, and therefore the same HCF. The numbers keep shrinking, so the process must end, and when the remainder reaches 0 the HCF is sitting right there.
Your turn
Use Euclid's algorithm to find the HCF of 867 and 255.
Solution: 867 = 255 × 3 + 102, then 255 = 102 × 2 + 51, then 102 = 51 × 2 + 0. The HCF is 51.
The LCM for free
For any two positive integers, HCF(a, b) × LCM(a, b) = a × b. So once you have the HCF, the LCM is one division away: LCM(455, 42) = \dfrac455 × 427 = 2730.
Your turn
Find the LCM of 84 and 126.
Solution: 126 = 84 × 1 + 42 and 84 = 42 × 2 + 0, so the HCF is 42. Then LCM = \dfrac84 × 12642 = 252.
Running it backwards
Working back up the steps writes the HCF as a combination of the two numbers. From the 455 and 42 example: 7 = 42 - 35 and 35 = 455 - 42 × 10, so 7 = 42 - (455 - 42 × 10) = 11 × 42 - 455. This is Bézout's identity, the key to proving Euclid's lemma, and it is exactly how RSA computes its secret keys.
Practice: master Euclid's algorithm
Guess first: Practice 1: In Euclid's algorithm for 252 and 105, what is the first remainder?
- 42
- 21
- 147
252 = 105 × 2 + 42, so the first remainder is 42.
Your turn
Practice 2: Continue: what is the HCF of 252 and 105?
Solution: 252 = 105 × 2 + 42, 105 = 42 × 2 + 21, 42 = 21 × 2 + 0. The HCF is 21.
Your turn
Practice 3: Two ropes are 391 cm and 255 cm long. They are cut into pieces of equal length, as long as possible, with nothing left over. How long is each piece, in cm?
Solution: 391 = 255 × 1 + 136, 255 = 136 × 1 + 119, 136 = 119 × 1 + 17, 119 = 17 × 7 + 0. Each piece is 17 cm (23 pieces and 15 pieces).
Guess first: Practice 4: HCF(a, b) = 12 and a × b = 2160. What is LCM(a, b)?
- 180
- 144
- 25920
HCF × LCM = a × b, so LCM = 2160 ÷ 12 = 180. For example a = 36, b = 60.
Your turn
Practice 5: How many divisions does Euclid's algorithm take for 89 and 55? Count every division, including the last one with remainder 0.
Solution: The remainders are 34, 21, 13, 8, 5, 3, 2, 1, 0: nine divisions. These are Fibonacci numbers, and consecutive Fibonacci numbers are the slowest possible case for Euclid's algorithm, every quotient is 1 (except the last).
Where this shows up in exams: AMC 10 / 12
HCF and LCM questions, often in disguise (gears, tiles, repeating patterns), appear regularly on the AMC 10 and AMC 12, and the algorithm handles large numbers that factor lists cannot.
Try it at home: the HCF race
- Pick two numbers between 100 and 1000.
- Divide the bigger number by the smaller one and write down the remainder.
- Now divide the smaller number by that remainder.
- Repeat until the remainder is 0.
- The last non-zero remainder is the HCF. Check it by dividing both numbers by it.
- Race a friend: one of you uses the algorithm, the other lists all the factors. Who finishes first?
Quick questions
What is Euclid's algorithm?
A method for finding the HCF (GCD) of two numbers by repeated division: divide, replace the pair by the smaller number and the remainder, and repeat until the remainder is 0. The last non-zero remainder is the HCF.
How do you find the HCF of 455 and 42 using Euclid's algorithm?
455 = 42 × 10 + 35, 42 = 35 × 1 + 7, 35 = 7 × 5 + 0, so the HCF is 7.
How do you get the LCM from the HCF?
Use HCF × LCM = a × b. For 455 and 42, the HCF is 7, so the LCM is 455 × 42 ÷ 7 = 2730.
Written by the EuclidCurve Smart Team. We are the maths and physics tutors behind EuclidCurve. We teach IB, AMC, ESAT and TMUA students in the UK, USA, UAE, Singapore and Hong Kong, and we write about the maths hiding in everyday life.