Maths & numbers

Greatest common divisor calculator

Find the largest positive integer that divides both numbers.

Your numbers

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your numbers and select Calculate.

Behind the numbers

How this calculation works

The Euclidean algorithm repeatedly replaces the larger problem with its remainder until the remainder is zero. Signs do not change the result. gcd(0, 0) is returned as 0 by convention.

THE FORMULAgcd(a, b) = gcd(b, a mod b)

A worked example

The greatest common divisor of 12 and 18 is 6.

Good to know

Uses the stated formula and assumptions. Displayed decimal values are rounded; use consistent units for all inputs.

A little curiosity

The remainder keeps the common factors

For 48 and 18, subtracting multiples gives remainders: 48 leaves 12 after division by 18, and 18 leaves 6 after division by 12. The next remainder is zero, so the greatest common divisor is 6. Replacing the pair with divisor and remainder preserves the common-divisor question.

The result can simplify a fraction. Dividing the numerator and denominator of 18/48 by their GCD, 6, gives 3/8 without changing the fraction’s value.

Whole numbers and sign conventions matter

The GCD is reported as non-negative; changing an input’s sign does not change its positive divisors. With one input zero, the GCD is the magnitude of the other. This tool uses 0 for gcd(0, 0) by convention.

The inputs must be safe whole numbers. Decimal measurements and approximate floating-point values do not have the same integer-divisibility interpretation.

A few questions, answered

Can I use negative integers?

Yes. Signs are ignored when finding the non-negative common divisor.

Is the GCD of two primes always 1?

Two different positive primes have GCD 1. A prime paired with itself has that prime as its GCD.

Find your calculator

Start typing to explore the library.