GCD Calculator

The greatest common divisor (GCD) of two numbers is the largest whole number that divides both with no remainder. It is also called the greatest common factor (GCF) or highest common factor (HCF). The GCD of 48 and 18 is 6, because 48 = 6 × 8 and 18 = 6 × 3, and 8 and 3 share no factor (see it worked out). Type two or more numbers to get the GCD, the LCM, and the steps by Euclid’s algorithm, prime factors, the ladder method or a list of factors.

Find the greatest common factor

Type two or more whole numbers, or paste a list such as 12, 18, 30. Results update as you type.

Examples:

How to Use This Calculator

  1. Type the numbers

    Put two numbers in a and b. Add up to six more, or paste a list such as 24, 36, 60.

  2. Read the GCD

    You also get the LCM, the numbers divided by the GCD, and whether they are coprime.

  3. Pick a method

    Euclid, prime factors, ladder or list factors: choose the one your class uses to see the steps.

What is the greatest common factor?

A factor of a number divides it exactly. The greatest common factor of two or more numbers is the largest factor they all have. Take 12 and 18. The factors of 12 are 1, 2, 3, 4, 6, 12. The factors of 18 are 1, 2, 3, 6, 9, 18. Both lists contain 1, 2, 3, 6, and the largest of those is 6, so GCF(12, 18) = 6.

The same number goes by three names. US schools call it the greatest common factor (GCF). The UK, India and Australia say highest common factor (HCF). Higher math and programming languages say greatest common divisor (GCD), as in Python’s math.gcd.

How to find the GCF: four methods

Each method below gives the same answer. The calculator shows all four for your numbers, so you can follow the one your teacher asked for. They are listed here in the same order as the calculator’s method buttons.

List the factors

Write every factor of each number, in pairs from the outside in: for 18, that is 1 × 18, 2 × 9 and 3 × 6. Then circle the factors on every list and take the largest. This is the first method most students learn, and it works well up to about 100. For bigger numbers the lists get long and it is easy to miss one.

List the factors of 12 and 18

Prime factorization

Split each number into primes. Keep only the primes that appear in every number, each at its lowest power, and multiply them. For 48 and 36:

48 = 2 × 2 × 2 × 2 × 3 = 2⁴ × 3
36 = 2 × 2 × 3 × 3 = 2² × 3²
GCF = 2² × 3 = 12

Both numbers have 2 and 3. The lower power of 2 is 2² (from 36) and the lower power of 3 is 3¹ (from 48), so the GCF is 4 × 3 = 12. Taking the higher powers instead, 2⁴ × 3² = 144, gives the least common multiple. The calculator’s prime table puts the two side by side.

Show the prime table for 48 and 36

The ladder method

The ladder (also called the cake or upside-down division method) is prime factorization done on all the numbers at once. Write the numbers in a row. Divide every one of them by a prime that goes into all of them, and write the results underneath. Repeat until no prime goes into every number in the bottom row. The GCF is the product of the primes down the left side.

Ladder for 36 and 60
2 36 60
2 18 30
3 9 15
3 5

3 and 5 share no prime, so the ladder stops. GCF(36, 60) = 2 × 2 × 3 = 12. For two numbers, the same ladder also gives the LCM: multiply the left side and the bottom row, 2 × 2 × 3 × 3 × 5 = 180.

Show the ladder for 36 and 60

Euclid’s algorithm

Euclid described this method around 300 BC, in Book VII of the Elements. It needs no factors at all. Divide the larger number by the smaller and keep the remainder. Then divide the old divisor by that remainder, and repeat. When the remainder reaches 0, the last divisor is the GCD. For 1071 and 462:

1,071 = 2 × 462 + 147
462 = 3 × 147 + 21
147 = 7 × 21 + 0

The remainder is 0 after 3 divisions, so GCD(1071, 462) = 21. It works because any number that divides both a and b also divides the remainder a − q × b, so the pair (b, remainder) has the same GCD as (a, b) but smaller numbers.

Show Euclid’s steps for 1071 and 462

Gabriel Lamé proved in 1844 that the number of divisions is never more than five times the number of digits in the smaller number, so even 40-digit numbers take at most 200 steps. The slowest pairs are consecutive Fibonacci numbers: 89 and 55 take 9 divisions, because every quotient is 1.

Euclid’s algorithm as a picture

Draw a 48 by 18 rectangle and cut off the largest square you can, 18 by 18. Two fit, leaving a 12 by 18 strip. Cut a 12 by 12 square from that, leaving 12 by 6. Two 6 by 6 squares fill it exactly. The side of the last square, 6, is the GCD, and the number of squares at each cut is a quotient in Euclid’s divisions. The calculator draws this rectangle for any two numbers.

Draw the rectangle for 48 and 18

Which method should you use?

The four methods compared
Method Good for Big numbers
List factors Numbers up to about 100, and first lessons Slow
Prime factors Getting the GCF and the LCM together Slow if a prime factor is large
Ladder Three or more numbers on paper Slow if a prime factor is large
Euclid Any two numbers, and computer programs Fast

GCF of three or more numbers

Work in pairs. Find the GCF of the first two numbers, then the GCF of that answer and the next number, and so on. For 24, 36 and 60, GCF(24, 36) = 12 and GCF(12, 60) = 12. The order does not change the result. With prime factors, a prime counts only if it appears in every number.

Three numbers can have a GCF of 1 even when some pairs share a factor. 6, 10 and 15 have GCF 1, yet 6 and 10 share 2, 6 and 15 share 3, and 10 and 15 share 5. The calculator points this out in its Coprime result.

Check 6, 10 and 15 in the calculator

GCF of common number pairs

These are the pairs that come up most in homework. Each pair opens in the calculator with its steps.

Greatest common factor and least common multiple of common pairs
Numbers GCF LCM Divided by GCF
6 and 8 2 24 3 : 4
8 and 12 4 24 2 : 3
9 and 12 3 36 3 : 4
12 and 16 4 48 3 : 4
12 and 18 6 36 2 : 3
14 and 21 7 42 2 : 3
15 and 25 5 75 3 : 5
16 and 24 8 48 2 : 3
18 and 24 6 72 3 : 4
18 and 27 9 54 2 : 3
20 and 30 10 60 2 : 3
24 and 36 12 72 2 : 3
32 and 48 16 96 2 : 3
36 and 48 12 144 3 : 4
42 and 56 14 168 3 : 4
45 and 60 15 180 3 : 4

GCF and LCM

The least common multiple (LCM) is the smallest number that all your numbers divide into. For two numbers, the GCF and the LCM are tied by one formula:

GCF(a, b) × LCM(a, b) = a × b
6 × 36 = 216 = 12 × 18

So once you have the GCF, the LCM is a × b ÷ GCF. The formula fails for three or more numbers: for 2, 4 and 8 the GCF is 2 and the LCM is 8, and 2 × 8 is not 2 × 4 × 8. Our LCM calculator explains the LCM on its own.

Simplifying fractions and ratios

Dividing the top and bottom of a fraction by their GCF puts it in lowest terms in one step. 48/36 has GCF 12, so 48/36 = 4/3. Ratios work the same way. A 1920 × 1080 screen has GCF 120, and 1920 ÷ 120 = 16 and 1080 ÷ 120 = 9, which is why it is called 16:9. The calculator’s “Divided by the GCD” result gives this lowest-terms ratio for any set of numbers.

Reduce 1920 × 1080 to 16:9

GCF word problems

A word problem needs the GCF when you split things into the largest possible equal groups, with nothing left over. If it asks when two things will line up again, it needs the LCM instead.

Gift bags

You have 24 pencils and 36 erasers and want identical gift bags with nothing left over. What is the largest number of bags? The number of bags must divide both 24 and 36, so it is GCF(24, 36) = 12. Each bag gets 24 ÷ 12 = 2 pencils and 36 ÷ 12 = 3 erasers.

Check the gift bags in the calculator

Square tiles

A floor is 360 cm by 270 cm. What is the largest square tile that covers it with no cutting? The tile’s side must divide both lengths, so it is GCF(360, 270) = 90 cm. That takes 4 × 3 = 12 tiles.

Draw the 360 by 270 floor

Teams

A class of 18 boys and 24 girls splits into teams, each with the same mix of boys and girls. The most teams possible is GCF(18, 24) = 6, each with 3 boys and 4 girls.

Coprime numbers

Numbers whose GCF is 1 are called coprime, or relatively prime. They do not have to be prime themselves: 8 and 15 are coprime, and so are 35 and 64. Two numbers next to each other, such as 20 and 21, are always coprime. A prime is coprime with every number it does not divide. Two even numbers are never coprime, because both have the factor 2.

Check 35 and 64 in the calculator

The extended Euclidean algorithm and Bézout’s identity

Bézout’s identity says that for any whole numbers a and b there are whole numbers x and y with a·x + b·y = GCD(a, b). The extended Euclidean algorithm finds them. It runs Euclid’s divisions and keeps two extra columns, s and t, so that each remainder r = s·a + t·b. Each new row is the row two up minus the quotient times the row above. For 240 and 46 the last row before the remainder 0 gives:

240 × (−9) + 46 × 47 = 2

Show the extended table for 240 and 46

When the GCD is 1, the identity gives a modular inverse: a number that undoes multiplication modulo b. For 17 and 3120, the inverse of 17 is 2753, because 17 × 2753 = 46,801, which is 15 × 3120 + 1. RSA encryption finds its private key this way, and programs use the same step to divide in modular arithmetic. If you work with remainders, our modulo calculator shows each one on a number line.

Find the inverse of 17 mod 3120

Zero and negative numbers

Every number divides 0, so GCD(a, 0) = a for any a that is not 0. GCD(0, 0) has no greatest divisor; some programming languages return 0 for it by convention, and the calculator asks for at least one number that is not 0. Signs do not matter either. The GCD is always positive, so GCD(−12, 18) = GCD(12, 18) = 6.

Frequently Asked Questions

What is the GCF of 12 and 18?

The GCF of 12 and 18 is 6. The factors of 12 are 1, 2, 3, 4, 6, 12, the factors of 18 are 1, 2, 3, 6, 9, 18, and the largest number on both lists is 6.

Show the factor lists of 12 and 18

How do you find the greatest common factor?

Find the largest number that divides all your numbers with no remainder. For small numbers, list the factors of each one and pick the biggest they share. For larger numbers, multiply the prime factors they have in common, or use Euclid’s algorithm: divide, then divide the divisor by the remainder, until the remainder is 0.

Is GCD the same as GCF and HCF?

Yes. Greatest common divisor (GCD), greatest common factor (GCF) and highest common factor (HCF) are three names for the same number. GCF is the usual name in US schools, HCF in the UK and India, and GCD in higher math and programming.

What does it mean when the GCF is 1?

It means the numbers are coprime, also called relatively prime: they share no factor except 1. Neither number has to be prime. 8 and 15 are coprime even though 8 = 2 × 2 × 2 and 15 = 3 × 5.

Check 8 and 15 in the calculator

How do you find the GCF of three numbers?

Find the GCF of two of them, then the GCF of that answer and the third number. For 24, 36 and 60: GCF(24, 36) = 12, and GCF(12, 60) = 12. The order does not matter. The ladder method also handles all three at once.

Show the ladder for 24, 36 and 60

How are the GCF and LCM related?

For two numbers, GCF × LCM = the product of the numbers. For 12 and 18: 6 × 36 = 216 = 12 × 18. So LCM = a × b ÷ GCF. This shortcut works for two numbers only, not for three or more.

What is the extended Euclidean algorithm used for?

It finds whole numbers x and y with a·x + b·y = GCD(a, b), for example 240 × (−9) + 46 × 47 = 2. When the GCD is 1, x is the inverse of a modulo b, which is how RSA encryption finds its private key and how programs divide in modular arithmetic.

Show the extended table for 240 and 46