GCD Calculator

Find the greatest common divisor (GCD, also called GCF or HCF) of two or more numbers and watch the Euclidean algorithm and the shared prime factors step by step.

What is the greatest common divisor (GCD)?

The greatest common divisor (GCD) of two or more whole numbers is the largest number that divides all of them exactly, with no remainder. It is also called the greatest common factor (GCF) or highest common factor (HCF). For example, the numbers that divide both 48 and 18 are 1, 2, 3 and 6, and the biggest of these is 6, so the GCD of 48 and 18 is 6. This GCD calculator finds the answer for two or more numbers and shows the Euclidean algorithm one step at a time, plus a Venn diagram of the prime factors for two numbers.

Properties of the GCD

  • The GCD is never larger than the smallest of the numbers, and it is always at least 1.
  • If the GCD is 1, the numbers are called coprime (or relatively prime). 35 and 18 are coprime even though neither is prime.
  • GCD(a, 0) = a, and GCD(a, a) = a.
  • GCD(a, b) × LCM(a, b) = a × b. For 48 and 18: 6 × 144 = 864 = 48 × 18.
  • The order of the numbers does not matter, and for more than two numbers you can combine them in pairs: GCD(a, b, c) = GCD(GCD(a, b), c).

How to find the GCD with the Euclidean algorithm

The Euclidean algorithm is the fastest method by hand, and it is the one used in the animated walk-through above. It rests on one fact: the GCD of two numbers does not change when you replace the larger number by its remainder after division by the smaller one. Take 252 and 105 as an example.

  1. Divide the larger number by the smaller one: 252 = 105 × 2 + 42. The remainder is 42.
  2. Now divide the previous divisor by that remainder: 105 = 42 × 2 + 21. The remainder is 21.
  3. Repeat: 42 = 21 × 2 + 0. The remainder is 0, so stop.
  4. The last non-zero remainder is the GCD. GCD(252, 105) = 21.
  5. Check: 252 = 21 × 12 and 105 = 21 × 5, and 12 and 5 have no common factor left.

How to find the GCD with prime factors

The second method writes each number as a product of primes. Then the GCD is the product of the primes the numbers share, each taken to the smaller of its powers. This is what the Venn diagram shows: the overlap holds the shared primes. For 48 = 2⁴ × 3 and 18 = 2 × 3², the shared part is 2 × 3 = 6, so GCD(48, 18) = 6. The Euclidean algorithm gives the same answer: 48 = 18 × 2 + 12, 18 = 12 × 1 + 6, 12 = 6 × 2 + 0.

GCD of three or more numbers

Find the GCD of the first two numbers, then find the GCD of that result and the third number, and so on. For 24, 36 and 60: GCD(24, 36) = 12, then GCD(12, 60) = 12. So the GCD of 24, 36 and 60 is 12.

Where the GCD is used

  • Simplifying fractions: divide the top and bottom by their GCD. For 36/84 the GCD is 12, so 36/84 = 3/7.
  • Simplifying ratios: 12 : 18 becomes 2 : 3 after dividing both by 6.
  • Tiling and cutting: the biggest square tile that exactly covers a 48 cm by 18 cm floor strip has a side of GCD(48, 18) = 6 cm, giving 8 × 3 = 24 tiles.
  • Sharing equally: the most groups you can make from 24 apples and 36 oranges with the same mix in each group is GCD(24, 36) = 12 groups.
  • Computer science: the GCD is used in cryptography (such as RSA key generation), in reducing rational numbers and in modular arithmetic.

Formulas Used

Euclidean algorithm

GCD(a, b) = GCD(b, a mod b), and GCD(a, 0) = a

Replace the pair by the smaller number and the remainder until the remainder is 0. The last non-zero value is the GCD.

Prime factor method

GCD = product of the shared primes, each to its smallest power

GCD(48, 18): 48 = 2⁴ × 3 and 18 = 2 × 3², so the GCD is 2 × 3 = 6.

Link with the LCM

GCD(a, b) × LCM(a, b) = a × b

Once you know the GCD you get the LCM for free: LCM(48, 18) = 48 × 18 ÷ 6 = 144.

Variables Explained

a, b

The two positive whole numbers being compared. For more numbers, repeat the method pair by pair.

q (quotient)

How many times the smaller number fits into the larger one in a division step.

r (remainder)

What is left after the division. The remainder is always smaller than the divisor.

GCD

The greatest common divisor, also called GCF or HCF.

Important Notes

•

This calculator works with positive whole numbers up to 1,000,000,000,000 and gives exact results. It is meant for learning, homework checks and everyday use.

•

For legal, financial or engineering work, check the result with a second method before you rely on it.

Frequently Asked Questions

Nothing. They are three names for the same thing: the largest number that divides all the given numbers exactly. GCD is common in textbooks and programming, GCF in US schools and HCF in UK and Indian schools.
Use the Euclidean algorithm: divide the larger number by the smaller, then divide the smaller by the remainder, and keep going until the remainder is 0. The last non-zero remainder is the GCD. For 48 and 18 it is 6.
The numbers are coprime: they share no prime factor, so their only common divisor is 1. For example GCD(35, 18) = 1. A fraction such as 35/18 cannot be simplified.
Divide the numerator and the denominator by their GCD. For 36/84 the GCD is 12, giving 3/7. The result is in lowest terms because 3 and 7 are coprime.
GCD(a, 0) = a, because every number divides 0 and the largest divisor of a is a itself. This is the stopping rule of the Euclidean algorithm.
For two numbers, GCD × LCM = the product of the numbers. With 12 and 18: GCD is 6, LCM is 36, and 6 × 36 = 216 = 12 × 18.
Yes. Enter all the numbers separated by commas. The calculator finds the GCD of the first two, then of that result with the third, and so on. The GCD of 24, 36 and 60 is 12.
Any number that divides both a and b also divides a − b × q, which is the remainder r. So the pair (a, b) and the pair (b, r) have exactly the same common divisors, and the numbers get smaller until one of them is 0.