How to Find the HCF: 4 Methods and Why Euclid’s Algorithm Wins
The highest common factor (HCF) can be found four ways. This guide works through each one, then looks closely at Euclid’s algorithm: why it works, why it needs so few steps, and where it is used today, from screen sizes to the encryption that protects your bank card.
By Basit MuradReviewed
Published 9 min read
Short answer
To find the HCF of two numbers, divide the larger by the smaller, then divide the smaller by the remainder, and repeat until the remainder is 0. The last number you divided by is the HCF. For 1,071 and 462: 1,071 = 2 × 462 + 147, 462 = 3 × 147 + 21, 147 = 7 × 21 + 0, so the HCF is 21.
HCF, GCF and GCD: one idea, three names
A factor of a number divides into it exactly. The highest common factor of two or more numbers is the largest number that is a factor of all of them. UK and Indian schools call it the highest common factor (HCF), American schools the greatest common factor (GCF), and mathematicians and programmers the greatest common divisor (GCD). They are the same number.
In word problems, the HCF is the answer whenever you split things into the largest possible equal groups, cut lengths into the longest equal pieces, or simplify a fraction or ratio. Its partner, the least common multiple, answers the opposite kind of question: when do repeating things line up again? That one has its own guide to the LCM.
Method 1: List the factors in pairs
List every factor of each number and pick the largest one they share. To avoid missing any, find factors in pairs: start at 1 and work up, writing each divisor with its partner, and stop when the pairs meet in the middle.
| Number | Factor pairs | All factors |
|---|---|---|
| 36 | 1 × 36, 2 × 18, 3 × 12, 4 × 9, 6 × 6 | 1, 2, 3, 4, 6, 9, 12, 18, 36 |
| 48 | 1 × 48, 2 × 24, 3 × 16, 4 × 12, 6 × 8 | 1, 2, 3, 4, 6, 8, 12, 16, 24, 48 |
The common factors are 1, 2, 3, 4, 6 and 12, so the HCF is 12. Listing is reliable for numbers up to about 100, the range set for sixth graders by the US Common Core standard 6.NS.B.4, but it gets slow quickly: 720 has 30 factors.
Method 2: Prime factorisation
Break each number into primes. Keep only the primes that appear in every number, each at the lowest power it appears, and multiply them. The lowest power is the most that all the numbers can share.
HCF of 360 and 756 by prime factors
Write each number as a product of primes, then take the shared primes at their lowest power.
- 360
- 2³ × 3² × 5
- 756
- 2² × 3³ × 7
- Shared primes
- 2 and 3 (5 and 7 are not shared)
- Lowest powers
- 2² and 3²
- HCF
- 4 × 9 = 36
HCF = 36
Taking the highest powers of every prime instead gives the LCM: 2³ × 3³ × 5 × 7 = 7,560.
Method 3: Euclid’s algorithm
Euclid described this method in Book VII, Proposition 2 of his Elements, written in Alexandria around 300 BC. Donald Knuth, in The Art of Computer Programming, called it the granddaddy of all algorithms, because it is the oldest non-trivial algorithm still in everyday use. It needs no factorising at all, only division.
- Divide the larger number by the smaller and note the remainder.
- Replace the larger number with the smaller one, and the smaller one with the remainder.
- Repeat until the remainder is 0. The last divisor is the HCF.
HCF of 1,071 and 462 by Euclid’s algorithm
Each line divides the previous divisor by the previous remainder.
- 1,071 ÷ 462
- 1,071 = 2 × 462 + 147
- 462 ÷ 147
- 462 = 3 × 147 + 21
- 147 ÷ 21
- 147 = 7 × 21 + 0
HCF = 21
Check: 1,071 = 21 × 51 and 462 = 21 × 22, and 51 and 22 share no factor.
Why it works
Any number that divides both 1,071 and 462 must also divide 1,071 − 2 × 462, which is the remainder 147. And any number that divides 462 and 147 must divide 1,071, because 1,071 = 2 × 462 + 147. So the pair (1,071, 462) has exactly the same common factors as the pair (462, 147), and therefore the same HCF. Each step swaps the pair for a smaller one with the same HCF, until one number divides the other exactly and the answer is obvious.
Euclid’s original version: repeated subtraction
Euclid himself subtracted the smaller number from the larger again and again, which is the same idea without division. Starting from 3,009 and 884, the example used in David Joyce’s edition of the Elements, subtraction takes 16 steps to reach the HCF of 17. Division does the same work in 4 steps: 3,009 = 3 × 884 + 357, 884 = 2 × 357 + 170, 357 = 2 × 170 + 17, and 170 = 10 × 17 + 0. Each division replaces a whole run of subtractions.
Method 4: The ladder for three or more numbers
Write the numbers in a row and divide by a prime that goes into every one of them. Repeat until no prime divides them all. The HCF is the product of the primes down the side.
| Divide by | Row of numbers |
|---|---|
| 2 | 84, 126, 210 |
| 3 | 42, 63, 105 |
| 7 | 14, 21, 35 |
| (stop) | 2, 3, 5 |
HCF = 2 × 3 × 7 = 42. The bottom row, 2, 3 and 5, shares no factor, which is how you know to stop. Multiply the HCF by the bottom row and you get the LCM: 42 × 2 × 3 × 5 = 1,260. You can also run Euclid’s algorithm in pairs: HCF(84, 126) = 42, then HCF(42, 210) = 42.
How fast is Euclid’s algorithm?
In 1844 the French mathematician Gabriel Lamé proved that Euclid’s algorithm never needs more division steps than five times the number of digits in the smaller number. The worst cases are consecutive Fibonacci numbers (1, 1, 2, 3, 5, 8, 13, 21…), where every quotient is 1 and the numbers shrink as slowly as possible. Lamé’s result is often cited as the start of computational complexity theory, the study of how long algorithms take.
| Pair | Digits in smaller | Division steps | Lamé’s limit |
|---|---|---|---|
| 13 and 8 | 1 | 5 | 5 |
| 89 and 55 | 2 | 9 | 10 |
| 987 and 610 | 3 | 14 | 15 |
| 17,711 and 10,946 | 5 | 20 | 25 |
| 2,178,309 and 1,346,269 | 7 | 30 | 35 |
Compare that with factorising. 999,999,999,989 is a prime number, so proving it has no smaller factor by trial division means testing every possible divisor up to 999,999. Euclid’s algorithm finds that its HCF with 999,999,999,958 is 1 in just 6 divisions. For numbers with hundreds of digits, factorising is effectively impossible, while Euclid’s algorithm still takes only a few thousand steps at most.
Where the HCF is used today
Screen sizes and aspect ratios
A screen’s aspect ratio is its resolution simplified by the HCF of its width and height. Doing the division shows that some ratios printed on the box are rounded.
| Resolution | HCF | Exact ratio | Usually sold as |
|---|---|---|---|
| 1920 × 1080 (Full HD) | 120 | 16:9 | 16:9 |
| 2560 × 1440 (QHD) | 160 | 16:9 | 16:9 |
| 3840 × 2160 (4K UHD) | 240 | 16:9 | 16:9 |
| 1366 × 768 | 2 | 683:384 | 16:9 |
| 1280 × 1024 | 256 | 5:4 | 5:4 |
| 2560 × 1080 | 40 | 64:27 | 21:9 |
| 3440 × 1440 | 80 | 43:18 | 21:9 |
| 1080 × 1350 (portrait social post) | 270 | 4:5 | 4:5 |
The 1366 × 768 laptop screen is very slightly wider than true 16:9, and the two “21:9” ultrawide resolutions aren’t the same shape as each other. The HCF makes the difference visible.
Making equal groups
A teacher has 48 pencils and 36 erasers and wants to make identical kits with nothing left over. The largest number of kits is HCF(48, 36) = 12, each with 48 ÷ 12 = 4 pencils and 36 ÷ 12 = 3 erasers. The same reasoning finds the largest square tile that fits a floor exactly, or the longest equal lengths two pieces of wood can be cut into.
Encryption
RSA, one of the encryption systems behind secure websites and card payments, uses Euclid’s algorithm at two points when a key is made. First it checks that the public exponent shares no factor with a number derived from the two secret primes. Then an extended form of the algorithm, which also keeps track of the quotients, works out the private key. In the classic textbook example with the primes 61 and 53, the derived number is 3,120 and the public exponent is 17. Euclid’s algorithm shows HCF(3,120, 17) = 1 in four divisions, and the extended version gives the private key 2,753, because 17 × 2,753 = 46,801, which is one more than 15 × 3,120. Real keys use primes more than 300 digits long, and the same algorithm handles them in a fraction of a second.
The HCF of fractions
The HCF of fractions in their simplest form is the HCF of the numerators divided by the LCM of the denominators. For 2/3 and 4/9 it is HCF(2, 4) ÷ LCM(3, 9) = 2/9. It is the largest fraction that goes into each a whole number of times: 2/3 is three lots of 2/9, and 4/9 is two.
Common mistakes
- Giving an answer larger than the smallest number. The HCF divides every number, so it can’t be bigger than the smallest of them.
- Taking shared primes at their highest power. For 12 = 2² × 3 and 18 = 2 × 3², the HCF is 2 × 3 = 6, not 36.
- Including a prime that isn’t in every number. In method 2 above, 5 and 7 each appear in only one number, so they stay out.
- Stopping Euclid’s algorithm one line early. Keep going until the remainder is 0; the HCF is the divisor on that last line.
- Treating an HCF of 1 as a mistake. It is a real answer: the numbers are coprime. Any two consecutive whole numbers, like 100 and 101, are coprime.
Check your working with the HCF Calculator. It takes up to 10 numbers, shows every division of Euclid’s algorithm and the prime factor method side by side, and lists all the common factors.
Open the HCF CalculatorFrequently asked questions
Is the HCF the same as the GCF and GCD?
Yes. Highest common factor (HCF), greatest common factor (GCF) and greatest common divisor (GCD) are three names for the same number. The name depends on the country and the level of maths, not on the method.
How do I know whether a word problem needs the HCF or the LCM?
If the problem splits, shares or cuts something into the largest equal parts, it needs the HCF, and the answer is no larger than the numbers you start with. If it asks when repeating events next happen together, or for the smallest amount that several sizes fit into, it needs the LCM, and the answer is at least as large as the biggest number.
Why are two consecutive numbers always coprime?
Any common factor of two numbers also divides their difference. Consecutive numbers differ by 1, and the only factor of 1 is 1, so their HCF must be 1.
What is the HCF of a number and 0?
By convention it is the number itself, because every number divides 0. So HCF(12, 0) = 12. That is also where Euclid’s algorithm ends: when the remainder reaches 0, the other number is the HCF. Our calculator asks you to leave 0 out, as it adds nothing to the answer.
How are the HCF and LCM connected?
For two numbers, HCF × LCM = the product of the numbers. For 84 and 120, the HCF is 12 and the LCM is 840, and 12 × 840 = 10,080 = 84 × 120. So once you have the HCF, the LCM is one division away. The HCF Calculator shows this check for any two numbers.
Sources
Calculators and guides
- HCF Calculator
- LCM Calculator
- Guide: How to Find the LCM: 5 Methods, Worked Examples and Real-Life Uses