Education & Study

GCD and LCM calculator

GCD and LCM of 2 to 20 numbers, with Euclid steps and prime factors.

  • Instant
  • Free
  • Private (processed locally)
  • No sign-up

Separate them with commas, spaces or semicolons.

Examples:
GCDGreatest common divisor
6
LCMLeast common multiple
36
Euclidean algorithm, step by step
Prime factorizations

ℹ️ Exact integer arithmetic (BigInt): no rounding, even for a huge LCM. 100% local, nothing is sent.

Find the GCD and LCM online, with the working shown

The greatest common divisor (GCD, also called HCF or GCF) and the least common multiple (LCM) are two cornerstones of arithmetic: you meet them in middle school with fractions, then again in number theory with Euclid’s algorithm and Bézout’s identity. This calculator handles 2 to 20 whole numbers and shows how the answer is reached: successive divisions, prime factorization, Bézout coefficients and the simplified fraction.

Finding them quickly matters whenever you simplify a fraction, add fractions with different denominators, work out when two repeating events coincide or cut material into identical squares. Students revising, parents checking homework, teachers preparing answer keys and programmers dealing with cycles, gear ratios or RSA keys all get an exact result plus the full method to copy down.

  1. Enter your numbers

    In the “Whole numbers (2 to 20)” field, type 2 to 20 integers separated by commas, spaces or semicolons, or click one of the examples.

  2. Read the GCD and LCM

    The two cards update as you type; the “Copy” button puts the raw number (no separators) on your clipboard.

  3. Check the properties

    Below the cards: whether the numbers are coprime (and, from three numbers on, whether they are pairwise coprime); for two numbers, the check GCD × LCM = a × b, the Bézout identity and the simplified fraction a/b.

  4. Open the explanations

    “Euclidean algorithm, step by step” lists every division a = q × b + r; “Prime factorizations” shows the minimum and maximum exponents.

How to find the GCD and LCM: Euclid’s algorithm and prime factors

The tool runs the Euclidean algorithm: divide the larger number by the smaller, a = q × b + r, then repeat with b and the remainder r, because gcd(a, b) = gcd(b, r). The last non-zero remainder is the GCD. The LCM follows without any factoring: lcm(a, b) = a × b ÷ gcd(a, b).

For more than two numbers the results are chained: gcd(a, b, c) = gcd(gcd(a, b), c), and likewise for the LCM. The prime factor panel gives the second classroom method: writing a = 2α × 3β × …, the GCD takes each common prime with its smallest exponent and the LCM takes every prime with its largest exponent.

  • a and b: the dividend and the divisor on each line (the larger number comes first).
  • q: the whole-number quotient; r: the remainder, always between 0 and b − 1.
  • GCD: the largest integer dividing every number; LCM: the smallest positive integer divisible by every number.
  • u and v: the Bézout coefficients, integers (possibly negative) with u × a + v × b = gcd(a, b), produced by the extended Euclidean algorithm.
  • α, β…: the exponents in the factorization, for example 12 = 22 × 31.

Worked examples of GCD and LCM

InputGCDLCMWhat the tool also shows
12, 186366 × 36 = 216 = 12 × 18; Bézout: (−1) × 12 + 1 × 18 = 6; 12/18 = 2/3
8, 12, 204120GCD(8, 12) = 4, then GCD(4, 20) = 4; LCM: 24, then 120
17, 311527Coprime; 11 × 17 + (−6) × 31 = 1
1071, 4622123,5623 divisions; (−3) × 1,071 + 7 × 462 = 21; 1,071/462 = 51/22
6, 10, 15130Coprime as a whole, but not pairwise (6 and 10 share 2)
2, 3, 5, 7, 11, 13, 17, 19, 231223,092,870Pairwise coprime: the LCM is the product

What are the GCD and LCM used for?

  • Fractions: simplify 12/18 to 2/3 by dividing by the GCD 6, or add 5/12 + 7/18 over the common denominator 36 = LCM(12, 18): 15/36 + 14/36 = 29/36.
  • Cycles and timetables: two buses leave together at 8:00, one every 12 minutes and one every 18; they leave together again at 8:36, after LCM = 36 minutes.
  • Cutting and tiling: to cover a 120 cm × 84 cm board with the largest possible squares and no waste, use GCD(120, 84) = 12 cm squares, 10 × 7 = 70 of them.
  • Gears and rhythms: gears with 12 and 18 teeth return to their starting position after 36 teeth have meshed, that is 3 turns of the small gear and 2 of the large one.
  • Cryptography: in RSA the public exponent e must be coprime with φ(n), and the private key d is its inverse modulo φ(n), found with Bézout. With e = 17 and φ(n) = 3,120, the tool shows (−367) × 17 + 2 × 3,120 = 1, so d = −367 + 3,120 = 2,753; indeed, 17 × 2,753 = 15 × 3,120 + 1.

Common mistakes

  • Mixing them up: the GCD is never larger than the smallest number and the LCM never smaller than the largest. For 12 and 18, a “GCD” of 36 is necessarily wrong.
  • Multiplying the numbers to get the LCM: 12 × 18 = 216, but the LCM is 36. The product of two numbers equals their LCM only when they are coprime (17 × 31 = 527).
  • Using GCD × LCM = product with three numbers: for 8, 12 and 20, 4 × 120 = 480, while 8 × 12 × 20 = 1,920.
  • Typing thousands separators: commas and spaces split the list, so “1,071” is read as two numbers, 1 and 71. Type 1071 instead.

Everything is computed locally in your browser with exact integer arithmetic (BigInt): no number is sent to any server. Limits: 2 to 20 non-zero whole numbers of up to 15 digits; the prime factorization is shown only when every prime factor can be found quickly (trial division up to 1,000,000, then a primality test).

Frequently asked questions

What is the difference between GCD and LCM?

The GCD (greatest common divisor, also called HCF or GCF) is the largest number that divides all your numbers; the LCM (least common multiple) is the smallest positive number that is a multiple of each of them. For 12 and 18, the common divisors are 1, 2, 3 and 6, so the GCD is 6; the common multiples are 36, 72, 108…, so the LCM is 36. Use the GCD to simplify fractions and the LCM to find a common denominator.

How does the Euclidean algorithm work?

Divide the larger number by the smaller, keep the remainder, then repeat with the divisor and that remainder until the remainder is 0. For 1,071 and 462: 1,071 = 2 × 462 + 147, then 462 = 3 × 147 + 21, then 147 = 7 × 21 + 0. The last non-zero remainder, 21, is the GCD, found in just 3 divisions instead of listing every divisor.

Why is GCD × LCM equal to a × b?

For two numbers, every prime factor appears once with its smaller exponent (in the GCD) and once with its larger exponent (in the LCM), which rebuilds a × b exactly. For 12 and 18: 6 × 36 = 216 = 12 × 18. The rule does not carry over to three or more numbers: for 8, 12 and 20, 4 × 120 = 480, while 8 × 12 × 20 = 1,920.

What does coprime mean?

Two numbers are coprime (relatively prime) when their GCD is 1, like 17 and 31; their LCM is then simply their product, 527. With three or more numbers the tool separates “coprime as a whole” from “pairwise coprime”: 6, 10 and 15 have an overall GCD of 1, yet 6 and 10 share the factor 2, so their LCM is 30, not the product 900.

What is Bézout’s identity used for?

It states that there are integers u and v with u × a + v × b = gcd(a, b); the tool finds them with the extended Euclidean algorithm, for example (−1) × 12 + 1 × 18 = 6. It is used to solve linear Diophantine equations ax + by = c and to compute modular inverses: 11 × 17 + (−6) × 31 = 1 shows that 11 is the inverse of 17 modulo 31. This is exactly how the private key is computed in RSA.

How do you find the GCD and LCM of three numbers?

Work two numbers at a time: GCD(8, 12, 20) = GCD(GCD(8, 12), 20) = GCD(4, 20) = 4, and LCM(8, 12, 20) = LCM(LCM(8, 12), 20) = LCM(24, 20) = 120. With prime factors, 8 = 2³, 12 = 2² × 3 and 20 = 2² × 5 give GCD = 2² = 4 and LCM = 2³ × 3 × 5 = 120. The tool accepts up to 20 non-zero whole numbers of up to 15 digits each, uses exact BigInt arithmetic with no rounding and ignores minus signs.