GCD Calculator
Calculate the Greatest Common Divisor of two numbers.
Calculator Inputs
Your Result
Enter your details and press Calculate to see your result.
Formula
How it works
- Enter two whole numbers.
- View their Greatest Common Divisor (GCD).
Share on Social Media:
Enter two whole numbers and the GCD Calculator returns their greatest common divisor: the largest number that divides both exactly. It's calculated with the Euclidean algorithm, so the answer is instant for any whole numbers up to about 9 quintillion (the 64-bit integer limit). You can copy the result, save it, or download it as CSV or PDF.
Worked example: GCD of 48 and 18
The Euclidean algorithm repeatedly replaces the larger number with the remainder after dividing by the smaller one:
- 48 ÷ 18 = 2 remainder 12
- 18 ÷ 12 = 1 remainder 6
- 12 ÷ 6 = 2 remainder 0
When the remainder reaches 0, the last non-zero remainder, 6, is the GCD. You can check: 48 = 6 × 8 and 18 = 6 × 3, and 8 and 3 share no common factor.
This method appears in Euclid's Elements (around 300 BC) and is still how computers calculate the GCD today. It's fast because the numbers shrink very quickly: even for numbers with hundreds of digits, it needs only a few hundred steps.
The other method: prime factors
At school you may have found the GCD by breaking numbers into primes:
- 48 = 2 × 2 × 2 × 2 × 3
- 18 = 2 × 3 × 3
Take the primes they share, as many times as both contain them: one 2 and one 3, so the GCD is 2 × 3 = 6. This is easy for small numbers, but factorising large numbers is very slow. That difficulty is what RSA encryption relies on. The Euclidean algorithm avoids factorising altogether.
Everyday uses
- Simplifying fractions. Divide top and bottom by the GCD: 48/18 ÷ 6 = 8/3.
- Simplifying ratios. A 1920 × 1080 screen has a GCD of 120, giving the familiar 16:9 aspect ratio.
- Splitting things evenly. With 48 red and 18 blue tiles, the largest number of identical groups you can make is 6, each with 8 red and 3 blue.
- Finding the LCM. For two numbers, LCM = (a × b) ÷ GCD. For 48 and 18: 864 ÷ 6 = 144.
Useful facts
- If the GCD is 1, the numbers are coprime (e.g. 8 and 15), even though neither is prime.
- GCD(a, 0) = a, because every number divides 0.
- For more than two numbers, work in pairs: GCD(a, b, c) = GCD(GCD(a, b), c).
- The GCD is the same whether the numbers are positive or negative, so it's always given as a positive number.