🔢 Maths

GCD Calculator

Calculate greatest common divisor of numbers.

Calculate gcd

Result
£0

How it works

The greatest common divisor of two whole numbers is the largest positive whole number that divides both of them with no remainder. It is the number you divide by when you cancel a fraction. School maths in England and Wales meets it under factors and simplifying fractions; the same idea is called highest common factor (HCF).

The Euclidean algorithm finds it without listing every factor. It stays exact for whole numbers. Decimals and fractions need to be scaled to integers first, otherwise “divides exactly” is not well defined.

Euclidean algorithm: replace the larger number by the remainder of larger ÷ smaller, and repeat until the remainder is 0. The last non-zero remainder is the GCD.

gcd(a, b) = gcd(b, a mod b), and gcd(a, 0) = a.

For three numbers, gcd(a, b, c) = gcd(gcd(a, b), c). The same pairing works for more than three. Listing prime factors also works: the GCD is the product of the shared primes, each taken to the lower power.

Worked example

gcd(48, 18). 48 = 2 × 18 + 12. 18 = 1 × 12 + 6. 12 = 2 × 6 + 0. The last non-zero remainder is 6, so gcd(48, 18) = 6.

The fraction 18/48 cancels by 6 to 3/8. For three numbers, gcd(48, 18, 30) = gcd(6, 30) = 6. Prime factors agree: 48 = 2⁴ × 3, 18 = 2 × 3², shared primes 2 × 3 = 6.

A related identity for two numbers is gcd(a, b) × lcm(a, b) = a × b. Here 6 × lcm(48, 18) = 864, so the least common multiple is 144. The LCM calculator does that side directly.

Questions and answers

What is the GCD of two primes?

1, unless they are the same prime. Numbers whose GCD is 1 are called coprime. You cannot cancel a fraction any further when the GCD of the top and bottom is 1.

Does order matter?

No. gcd(18, 48) is the same as gcd(48, 18). The algorithm swaps them on the first step if you start with the smaller one.

Can I use this for measurements in centimetres?

Yes, if both lengths are whole millimetres or whole centimetres. The GCD is the longest equal piece you can cut both lengths into without a remainder. Mixed units (one in inches, one in centimetres) must be converted first.

Why did a spreadsheet give a different answer?

Most sheets have a GCD function for integers. If a cell is 18.0 stored as text, or a number has been rounded, the remainder changes. Stick to integers. For polynomials or decimals, this page is the wrong tool.