GCD Calculator

What is the largest number that divides all your inputs evenly?

Enter two or more integers and instantly find their greatest common divisor (GCD). See the prime factorization and understand why the result is correct — useful for simplifying fractions, solving ratio problems, and working with divisibility.

Updated July 2026 · How this works

Example calculation — edit any field to use your own numbers

Worth knowing
How It Works
The formula, explained simply

Think of the GCD as the size of the largest identical tile you can use to perfectly cover two different-length walls without cutting any tile. If one wall is 36 cm and another is 48 cm, the largest tile that fits both without cutting is 12 cm. That is the GCD — not a theoretical concept but a physical constraint on how things divide evenly.

The Euclidean algorithm computes this by repeated subtraction expressed as division with remainder. At each step, you replace the larger number with the remainder from dividing it by the smaller. The process terminates because remainders strictly decrease with each step, and it terminates at zero, leaving behind the GCD. For numbers with hundreds of digits, this algorithm still finishes in microseconds because the number of steps grows only logarithmically with the size of the inputs.

When you extend GCD to three or more numbers, you apply it sequentially: find the GCD of the first two, then find the GCD of that result with the third number, and so on. This works because GCD is associative — the order of operations does not affect the answer. The tool handles this automatically when you enter optional third or fourth numbers.

When To Use This
Right tool, right situation

Use the GCD calculator when you need to simplify fractions to lowest terms, reduce a ratio to its smallest integer form, or figure out how to split multiple quantities into the maximum number of equal groups. It also appears in cryptography (checking that a public key exponent and phi(n) are coprime) and in computer science when computing hash table sizes or stride lengths for memory access patterns.

The GCD is also useful for checking whether two measurements are commensurable — that is, whether they share a rational ratio. If GCD(a, b) is large relative to both numbers, the quantities are closely related by simple whole-number multiples. If GCD returns 1, the measurements are in an irreducible ratio.

Do not use this tool when your inputs are not integers. Floating-point numbers, measurements with decimal precision, or irrational quantities like pi or square roots do not have a GCD in the classical sense. In those cases, you need a numerical approximation method, not the Euclidean algorithm. Also, GCD is not the right tool when you are looking for the smallest shared multiple — that is the LCM, which is a distinct calculation even though the two are mathematically related.

Common Mistakes
Why results sometimes look wrong

Confusing GCD with LCM. The greatest common divisor and the least common multiple are related but opposite in direction. GCD finds the largest factor shared by all numbers; LCM finds the smallest multiple shared by all numbers. A common mistake when adding fractions is dividing by GCD when you should be multiplying by LCM for the denominator. They are connected by the identity: GCD(a, b) x LCM(a, b) = a x b.

Assuming coprime means prime. Saying two numbers have GCD 1 only means they share no common prime factor. Both numbers can be composite — 8 and 9 are coprime because 8 = 2 x 2 x 2 and 9 = 3 x 3 share no prime. If you use the GCD result to argue that a number is prime itself, that conclusion does not follow.

Applying GCD to non-integers. GCD is defined only for integers. Entering a decimal like 3.5 and 7 does not produce a meaningful result. In practice, if you need the GCD of rational numbers, convert them to integers first by multiplying through by the common denominator. This calculator explicitly rejects decimal inputs to prevent silent wrong answers.

The Math
Worked examples and deeper derivation

The formal definition: GCD(a, b) is the largest integer d such that d divides a and d divides b. Every common divisor of a and b also divides GCD(a, b) — this makes GCD the generator of the set of all common divisors.

The Euclidean algorithm expressed as a recurrence: GCD(a, b) = GCD(b, a mod b), with base case GCD(a, 0) = a. Each step reduces the problem size because the remainder is always strictly less than the divisor. The number of division steps is at most five times the number of decimal digits in the smaller input — a bound proven by Gabriel Lame in 1844, making this one of the oldest complexity analyses in mathematics.

For multiple inputs, GCD(a, b, c) = GCD(GCD(a, b), c). The simplified ratio displayed by this tool divides each original number by the GCD, producing the smallest-integer representation of their proportional relationship. If GCD(a, b) = 1, the ratio a:b is already in its simplest form and cannot be reduced further without introducing fractions.

Simplifying a fraction before a math exam
First Number: 84, Second Number: 112
The GCD is 28. Dividing both the numerator 84 and denominator 112 by 28 gives the fully reduced fraction 3/4. This is the fastest path to simplest form — no trial and error needed.
Splitting supplies evenly into identical groups
First Number: 120 (apples), Second Number: 90 (oranges), Third Number: 60 (bananas)
The GCD of 120, 90, and 60 is 30. You can make exactly 30 identical bags, each containing 4 apples, 3 oranges, and 2 bananas — with nothing left over. This is the maximum number of equal groups possible.
A software engineer finding tile sizes for a screen layout
First Number: 1920 (screen width in pixels), Second Number: 1080 (screen height in pixels)
The GCD of 1920 and 1080 is 120. The aspect ratio simplifies to 16:9, confirming standard HD resolution. Engineers use GCD to detect aspect ratios without floating-point errors — this is the integer-exact method.
Expert Unlock
The thing most explanations skip

The Euclidean algorithm assumes exact integer arithmetic — it produces exact results because integers have no rounding error. At the boundary, numbers near the limit of JavaScript safe integers (above 2^53 - 1, roughly 9 quadrillion) will silently lose precision because JavaScript represents all numbers as 64-bit floats. For inputs above roughly 1 billion, this calculator warns you; for cryptographic applications where 1024-bit or 2048-bit integers are involved, you need a big-integer library, not floating-point arithmetic. The Euclidean algorithm itself is correct at any precision — the constraint is the representation, not the algorithm.

What does the GCD actually tell you — and when does it matter?

What is the GCD of two numbers?
The greatest common divisor (also called the highest common factor or HCF) is the largest positive integer that divides both numbers without leaving a remainder. For example, the GCD of 18 and 24 is 6, because 6 divides both evenly and no larger number does. Every pair of positive integers has exactly one GCD.
What does it mean when the GCD is 1?
When the GCD equals 1, the two numbers are called coprime or relatively prime — they share no common prime factors. This does not mean either number is prime itself: 8 and 9 are coprime even though neither is prime. Coprime numbers cannot be simplified further as a ratio or fraction.
How is GCD calculated using the Euclidean algorithm?
The Euclidean algorithm repeatedly divides the larger number by the smaller and replaces the larger with the remainder until the remainder is zero. The last non-zero remainder is the GCD. For 48 and 36: 48 = 36 x 1 + 12, then 36 = 12 x 3 + 0, so GCD is 12. This method works in logarithmic time and is exact for any pair of integers.

Need something this doesn't cover?

Suggest a tool — we'll build it →