ToolNimba

๐Ÿ”ข GCD Calculator: Greatest Common Divisor of Any Numbers

Shihab Mia By Shihab Mia ยท Updated 2026-07-17

GCD (greatest common divisor)
-
LCM (least common multiple)
-
Numbers used
-
Values
-
Euclidean algorithm, first pair
Step a b a mod b
Prime factorization view

Enter two or more integers to find their GCD and LCM.

The greatest common divisor of two integers is the largest whole number that divides both with no remainder: the GCD of 48 and 36 is 12. This GCD calculator returns that value the moment you type. Enter two or more integers separated by commas, spaces, or new lines and you get the greatest common divisor, the least common multiple, the full Euclidean algorithm reduction line by line, and the shared prime factors that build the answer. It handles long lists, negative signs, and numbers far too large to factor by hand, and it works equally as a GCF calculator or an HCF calculator, since those are the same quantity under different names. Everything below explains the four standard methods, the properties that let you sanity check a result, and where the GCD actually shows up.

What is the GCD Calculator?

The greatest common divisor of a set of integers is the largest positive whole number that divides every one of them without a remainder. It is the same value people call the GCF (greatest common factor) or the HCF (highest common factor); the names differ but the answer is identical. For 48, 36, and 60 the greatest common divisor is 12, because 12 is the biggest number that goes evenly into all three. Any GCD calculator worth using should return that value along with the reasoning, not just a bare number. Formally the GCD is defined for integers not all zero, it is always at least 1, and it is never larger than the smallest non-zero absolute value in the set. Those two bounds alone catch most arithmetic slips.

There are four standard ways to find it, and this page uses the fastest two while showing the working for both. The first is listing factors: write out every divisor of each number and pick the biggest one they share. For 12 (1, 2, 3, 4, 6, 12) and 18 (1, 2, 3, 6, 9, 18) the shared divisors are 1, 2, 3, 6, so the greatest common divisor is 6. It is intuitive and fine for small numbers, but it collapses immediately once the inputs get large, because finding every factor of a big number is far harder than finding the GCD directly.

The second is the prime factorization method. Every integer above 1 breaks into a unique product of primes, a result known as the fundamental theorem of arithmetic, and the GCD is built from the primes shared by all of the numbers, each raised to the lowest power that appears in any of them. For 48 = 2^4 x 3 and 36 = 2^2 x 3^2, the shared primes are 2 (at the smaller exponent, 2) and 3 (at exponent 1), so the greatest common divisor is 2^2 x 3 = 12. The LCM is the mirror image: take every prime that appears anywhere, at its highest power, giving 2^4 x 3^2 = 144. This calculator prints each number's factorization so you can see exactly where the answer comes from. A classroom variant of the same idea is the ladder or cake method, where you divide the whole row by a common prime, write the quotients underneath, and repeat; the product of the primes down the left side is the GCD, and multiplying that by the leftover row gives the LCM.

The third and fastest method is the Euclidean algorithm, which is what this euclidean algorithm calculator runs under the hood. The rule is gcd(a, b) = gcd(b, a mod b): you repeatedly replace the pair with the smaller number and the remainder of dividing them, and when the remainder reaches zero the last non-zero value is the answer. For example gcd(1071, 462) becomes gcd(462, 147), then gcd(147, 21), then gcd(21, 0) = 21. Three steps, no factoring. It works because any number dividing both a and b must also divide a - qb, so the common divisors never change as you reduce. Lame's theorem bounds the cost: the number of division steps is never more than about five times the digit count of the smaller number, which is why the method stays instant even on numbers hundreds of digits long. The fourth method, the binary or Stein algorithm, replaces division with halving and subtraction and is what some low-level libraries use for speed, but it returns the identical value.

To handle three or more inputs, the greatest common divisor is folded across the list one pair at a time, since gcd(a, b, c) = gcd(gcd(a, b), c). Order does not matter, and you can stop early: once a running GCD hits 1, the answer for the whole set is 1. The same folding idea gives the least common multiple through the identity lcm(a, b) = |a x b| / gcd(a, b), so this tool works as a combined gcd and lcm calculator. A caution on that identity: it is a two-number rule only. For three or more numbers, gcd x lcm does not equal the product, so fold the LCM pairwise as well rather than multiplying everything together. A related extension, the extended Euclidean algorithm, also finds integers x and y with ax + by = gcd(a, b), which is Bezout's identity; that pair is what makes modular inverses and RSA key generation possible.

The everyday use of the greatest common divisor is reducing fractions to lowest terms: divide the numerator and denominator by their GCD and the fraction is fully simplified in one step rather than by repeated halving. The same move simplifies ratios and aspect ratios, so 1920:1080 becomes 16:9 once you divide by their GCD of 120. Beyond arithmetic it drives gear and pulley ratios, tiling and packing questions where you want the largest square that fills a rectangle with no offcuts, scheduling problems where two cycles must line up, music theory rhythm subdivisions, and cryptography, where RSA requires the public exponent to be coprime with a particular value, meaning their GCD must be exactly 1. Programming languages ship it directly: Python has math.gcd, which accepts any number of arguments, and JavaScript developers typically write a three-line Euclidean loop with BigInt for large values. Whenever you need the largest common measure of several whole numbers, the greatest common divisor is the tool for the job, and this page computes it in real time as you type.

When to use it

  • Reducing a fraction to lowest terms by dividing the top and bottom by their greatest common divisor.
  • Simplifying a ratio such as 1920:1080 down to 16:9 using the GCD of the two terms.
  • Checking greatest common divisor homework and seeing the Euclidean algorithm steps behind the answer.
  • Finding the largest identical tile or block size that fits two dimensions with no offcuts.
  • Confirming two numbers are coprime (GCD of 1) before using them as a modulus and exponent pair.
  • Simplifying gear ratios, sampling rates, or recipe scale factors down to their smallest whole-number form.

How to use the GCD Calculator

  1. To find the GCD, type two or more integers into the box, separated by commas, spaces, or new lines.
  2. Read the greatest common divisor and the least common multiple shown immediately.
  3. Scan the Euclidean algorithm table to see how the first pair reduces step by step.
  4. Check the prime-factorization view to see which shared factors build the GCD.
  5. Sanity check the result: the GCD must divide every input, and cannot exceed the smallest of them.
  6. Use Copy result to grab the GCD and LCM, or an example button to load a sample set.

Formula & method

Euclidean algorithm: gcd(a, b) = gcd(b, a mod b), repeated until the remainder is 0; the last non-zero value is the greatest common divisor. Prime method: multiply each shared prime at its lowest exponent. For three or more numbers, fold pairwise: gcd(a, b, c) = gcd(gcd(a, b), c). The least common multiple follows from lcm(a, b) = |a × b| / gcd(a, b), a two-number identity only.
Euclidean algorithm: gcd(48, 36) = 12gcd(48, 36)gcd(36, 12)= 1248 mod 36 = 1236 mod 12 = 0Prime view48 = 2 x 2 x 2 x 2 x 336 = 2 x 2 x 3 x 3shared: 2 x 2 x 3GCD = 12

Worked examples

Find the greatest common divisor of 48 and 36.

  1. gcd(48, 36): 48 mod 36 = 12, so gcd(48, 36) = gcd(36, 12)
  2. 36 mod 12 = 0, so gcd(36, 12) = 12
  3. Check by primes: 48 = 2^4 x 3, 36 = 2^2 x 3^2, shared = 2^2 x 3 = 12
  4. Sanity check: 12 divides both, and 12 is not larger than 36

Result: GCD = 12 (and LCM = 48 x 36 / 12 = 144)

Find the greatest common divisor of 1071 and 462 with the Euclidean algorithm.

  1. 1071 mod 462 = 147, so gcd(1071, 462) = gcd(462, 147)
  2. 462 mod 147 = 21, so gcd(462, 147) = gcd(147, 21)
  3. 147 mod 21 = 0, so the answer is the last non-zero value, 21

Result: GCD = 21

Simplify the fraction 84/126 to lowest terms.

  1. Find the GCD: 126 mod 84 = 42, then 84 mod 42 = 0, so gcd(84, 126) = 42
  2. Divide the numerator: 84 / 42 = 2
  3. Divide the denominator: 126 / 42 = 3
  4. The result 2/3 cannot reduce further because gcd(2, 3) = 1

Result: 84/126 = 2/3 in one step

Greatest common divisor and LCM for common integer pairs

NumbersGCDLCM
8 and 12424
12 and 18636
48 and 3612144
1071 and 4622123562
15 and 25575
9 and 281252
100 and 8020400
1920 and 108012017280

Euclidean algorithm reduction for gcd(1071, 462)

Stepaba mod b
11071462147
246214721
3147210

Four methods for finding the greatest common divisor

MethodHow it worksBest forWeakness
Listing factorsWrite every divisor of each number, take the largest shared oneNumbers under about 100Unusable once numbers get large
Prime factorizationMultiply shared primes at their lowest exponentsShowing why the answer is what it isFactoring large numbers is slow
Ladder / cake methodDivide the whole row by a common prime, repeat, multiply the left columnClassrooms, and getting GCD and LCM togetherStill needs you to spot primes by eye
Euclidean algorithmReplace the pair with (b, a mod b) until the remainder is 0Any size of number, including hundreds of digitsGives no factorization insight on its own

Common mistakes to avoid

  • Confusing the greatest common divisor with the least common multiple. The GCD is never larger than the smallest number you entered, while the LCM is never smaller than the largest. If your greatest common divisor came out bigger than an input, you have the two swapped.
  • Assuming the GCD of coprime numbers is an error. When numbers share no common prime factor, such as 9 and 28, the greatest common divisor is 1. That is a correct, meaningful result, not a failure to find one.
  • Stopping the Euclidean algorithm one step early. The answer is the last non-zero remainder, taken when the remainder becomes exactly 0. Stopping when the remainder is still positive gives a divisor, but not the greatest one.
  • Multiplying shared primes at the wrong power. When building the greatest common divisor from prime factors, use the lowest exponent each shared prime reaches. Using the higher exponent overshoots and no longer divides both numbers. The highest exponents give the LCM, not the GCD.
  • Using gcd x lcm = product on three or more numbers. That identity holds for exactly two numbers. For 4, 6, and 10 the GCD is 2 and the LCM is 60, but the product is 240, not 120. Fold both quantities pairwise instead.
  • Including zero or decimals in the list. The greatest common divisor is defined for integers not all zero, and zero is divisible by every integer. This calculator ignores zeros and decimals so the result stays well defined. If you need a common measure of decimals, scale them to whole numbers first.

Glossary

Greatest common divisor (GCD)
The largest positive integer that divides every number in a set without a remainder. Also written GCF or HCF.
Greatest common factor (GCF)
Another name for the greatest common divisor; factor and divisor mean the same thing here.
Highest common factor (HCF)
The British term for the greatest common divisor. GCD, GCF, and HCF all give the same value.
Euclidean algorithm
A fast method for the GCD that repeatedly replaces the pair with the smaller number and the remainder of dividing them, until the remainder is zero.
Extended Euclidean algorithm
A version that also returns integers x and y with ax + by = gcd(a, b), used for modular inverses and RSA key generation.
Bezout's identity
The fact that for any integers a and b there exist integers x and y such that ax + by equals their greatest common divisor.
Least common multiple (LCM)
The smallest positive integer that every number in the set divides into evenly, found from |a x b| / gcd(a, b) for two numbers.
Coprime (relatively prime)
Two integers whose only common divisor is 1, so their greatest common divisor is 1 (for example 9 and 28).
Prime factorization
Writing an integer as a product of prime numbers; the GCD uses the primes shared by all inputs at their lowest powers.
Divisor
A whole number that divides another exactly, leaving no remainder.

Frequently asked questions

What is a GCD calculator?

A GCD calculator finds the greatest common divisor of two or more integers, meaning the largest whole number that divides all of them evenly. This one also shows the Euclidean algorithm steps, the LCM, and the shared prime factors.

How do you find the greatest common divisor of two numbers?

To find the gcd of two numbers, use the Euclidean algorithm: divide the larger by the smaller, keep the remainder, then repeat with the smaller number and that remainder. When the remainder hits zero, the last non-zero value is the greatest common divisor.

What is the GCD of 48 and 36?

The greatest common divisor of 48 and 36 is 12. Both numbers are divisible by 12, and no larger number divides both, since 48 = 2^4 x 3 and 36 = 2^2 x 3^2 share exactly 2^2 x 3.

Is the GCD the same as the GCF or HCF?

Yes. Greatest common divisor (GCD), greatest common factor (GCF), and highest common factor (HCF) are three names for the same value, so this page doubles as a gcf calculator and an hcf calculator. GCD is more common in number theory and computing, GCF in US schools, HCF in the UK and India.

Can the greatest common divisor be 1?

Yes. When numbers share no common factor other than 1 they are called coprime or relatively prime, so their GCD is 1. For example, the greatest common divisor of 9 and 28 is 1. Two different primes are always coprime.

What is the difference between the Euclidean algorithm and the prime factorization method?

Both give the same greatest common divisor, but the Euclidean algorithm only needs a few divisions and works on numbers of any size, while the prime factorization method requires you to factor each number first, which becomes impractical for large inputs. Use primes to understand the answer, and the Euclidean algorithm to get it.

Does this calculator handle more than two numbers?

Yes. Enter any list of integers and the tool folds the greatest common divisor across all of them one pair at a time, using gcd(a, b, c) = gcd(gcd(a, b), c). Once the running GCD reaches 1, the answer for the whole set is 1.

How is the GCD used to simplify fractions?

Divide the numerator and denominator by their greatest common divisor. For 48/36, dividing both by the GCD of 12 gives 4/3, the fraction in lowest terms, in a single step. A fraction is fully reduced exactly when the GCD of its numerator and denominator is 1.

What is the relationship between GCD and LCM?

For two numbers, greatest common divisor times least common multiple equals their product: gcd(a, b) x lcm(a, b) = a x b. That is why finding the GCD immediately gives you the LCM. The identity does not extend to three or more numbers.

Does the greatest common divisor change if I enter negative numbers?

No. The GCD is defined as a positive value based on magnitude, so the calculator uses the absolute value of each entry. The greatest common divisor of -48 and 36 is the same as that of 48 and 36, namely 12.

What is the GCD of a number and itself, or of a number and 1?

The greatest common divisor of any number with itself is that number, since gcd(n, n) = n. The GCD of any number with 1 is always 1, because 1 has no other divisors. Also, if one number divides the other exactly, the smaller number is the GCD.

How do I calculate the GCD in Python or JavaScript?

In Python use math.gcd, which takes any number of integer arguments: math.gcd(48, 36, 60) returns 12. JavaScript has no built-in, so write a Euclidean loop: while (b) { [a, b] = [b, a % b]; } return Math.abs(a); which works with BigInt for very large values.