LCM & GCD Calculator

Enter one positive integer per row to find the greatest common divisor (GCD) and least common multiple (LCM). Add or remove rows, or paste a list separated by commas, spaces, newlines, tabs or semicolons.

GCD (GCF) — greatest common divisor
6
LCM — least common multiple
36
Numbers entered
2
GCD(12, 18) = 6; LCM = (12 × 18) ÷ 6 = 36

FreeNo sign-upPrivate — runs in your browser, nothing is uploaded

Checked against 17 reference cases · Wikipedia · Reviewed · Updated · How we check

Quick answer

The GCD (greatest common divisor) is the largest integer that divides every number with no remainder, and the LCM (least common multiple) is the smallest positive integer that every number divides into evenly. For two numbers a and b the key identity is LCM(a, b) = (a × b) / GCD(a, b); for example GCD(12, 18) = 6, so LCM(12, 18) = (12 × 18) / 6 = 216 / 6 = 36. For longer lists both values are folded pairwise: GCD(a, b, c) = GCD(GCD(a, b), c) and the same nesting applies to the LCM.

Formula & method

LCM(a, b) = (a · b) / GCD(a, b)
  • a, b — the two positive integers being compared
  • GCD(a, b) — greatest common divisor (largest number dividing both)
  • LCM(a, b) — least common multiple (smallest number both divide into)

For positive integers, divide a by the GCD before multiplying by b. The tool uses exact integer arithmetic and rejects inputs or LCM results above 9,007,199,254,740,991 instead of rounding them.

GCD(a, b) = GCD(b, a mod b),  GCD(a, 0) = a

Euclid's algorithm: repeatedly replace the larger number by the remainder of dividing the two until one becomes zero. The non-zero survivor is the GCD.

GCD(a, b, c, …) = GCD(GCD(a, b), c, …);  LCM(a, b, c, …) = LCM(LCM(a, b), c, …)

For three or more numbers, fold the operation pairwise from left to right. The result is independent of the order you process the values.

Examples

Example 1: Two numbers (the default)

Input
12, 18
Result
GCD = 6, LCM = 36
Why
Euclid: GCD(12, 18) → GCD(18, 12) → GCD(12, 6) → GCD(6, 0) = 6. Then LCM = (12 × 18) / 6 = 216 / 6 = 36. So 36 is the smallest number that both 12 and 18 divide into evenly (36 ÷ 12 = 3, 36 ÷ 18 = 2).

Example 2: Three numbers

Input
8, 12, 20
Result
GCD = 4, LCM = 120
Why
GCD: GCD(8, 12) = 4, then GCD(4, 20) = 4. LCM: LCM(8, 12) = (8 × 12) / 4 = 24, then LCM(24, 20) = (24 × 20) / GCD(24, 20) = 480 / 4 = 120. Check: 120 ÷ 8 = 15, 120 ÷ 12 = 10, 120 ÷ 20 = 6.

Example 3: Pair with a shared factor

Input
15, 25
Result
GCD = 5, LCM = 75
Why
15 = 3 × 5 and 25 = 5 × 5 share only the factor 5, so GCD = 5. LCM = (15 × 25) / 5 = 375 / 5 = 75. (If the numbers had no common factor at all, the GCD would be 1 and the LCM would simply be their product.)

Example 4: Four numbers with a shared factor

Input
4, 6, 8, 12
Result
GCD = 2, LCM = 24
Why
GCD folds to 2: GCD(4, 6) = 2, GCD(2, 8) = 2, GCD(2, 12) = 2. LCM folds to 24: LCM(4, 6) = 12, LCM(12, 8) = (12 × 8) / 4 = 24, LCM(24, 12) = 24. So 24 is the smallest common multiple of all four values.

When to use this tool

  • Adding or subtracting fractions: the LCM of the denominators gives the least common denominator, the smallest denominator you can convert every fraction to.
  • Simplifying a fraction or ratio to lowest terms by dividing the numerator and denominator by their GCD.
  • Solving scheduling and cycle problems — e.g. two events that repeat every 8 and 12 days next coincide after LCM(8, 12) = 24 days.
  • Splitting quantities into the largest equal groups (GCD) or finding gear, packaging, or tiling sizes that line up evenly.

Common mistakes

  • Multiplying all the numbers to get the LCM. The product is always *a* common multiple but rarely the *least* one — 12 × 18 = 216 is a common multiple, but the LCM is only 36. Always divide by the GCD.
  • Confusing GCD with LCM. The GCD is never larger than the smallest input, while the LCM is never smaller than the largest input. If your 'GCD' exceeds an input, you computed the wrong one.
  • Entering decimals or fractions. GCD and LCM are defined for whole numbers (integers) only. Values like 2.5 or 3/4 are rejected — scale them to integers first if needed.
  • Including zero in the list. LCM is undefined when any value is 0 (zero has no positive multiples in common), so this tool requires positive integers and ignores blanks.

Frequently asked questions

What is the difference between GCD and LCM?

The GCD (greatest common divisor, also called GCF or HCF) is the largest number that divides all of your inputs without a remainder, so it is always ≤ the smallest input. The LCM (least common multiple) is the smallest positive number that all of your inputs divide into evenly, so it is always ≥ the largest input. For 12 and 18 the GCD is 6 and the LCM is 36.

Is GCD the same as GCF or HCF?

Yes. GCD (greatest common divisor), GCF (greatest common factor), and HCF (highest common factor) are three names for the exact same quantity. Different textbooks and countries prefer different abbreviations, but they all mean the largest integer that divides every number in the set.

How does the calculator find the GCD so fast?

It uses Euclid's algorithm, which repeatedly replaces the larger number with the remainder of dividing the pair until one of them is zero — the other value is then the GCD. It is dramatically faster than listing factors and works in just a handful of steps even for very large numbers.

Why isn't the LCM just all the numbers multiplied together?

Because the product double-counts any shared factors. For 12 and 18 the product is 216, but both share a factor of 6, so the true LCM is 216 ÷ 6 = 36. The correct formula is LCM(a, b) = (a × b) / GCD(a, b), which removes the overlap.

Can I find the LCM or GCD of more than two numbers?

Yes. Add rows or paste a list separated by commas, spaces, newlines, tabs or semicolons. Do not include thousands separators. The tool combines values pairwise, independent of their order. Each input and the final LCM must be at most 9,007,199,254,740,991; very long lists may take time.

What happens if I enter a decimal, a fraction, or zero?

This tool accepts positive integer values and ignores blank rows. Integer-valued decimal or exponent notation such as 12.0 or 1.2e1 is accepted. Non-integer values, fractions such as 3/4, zero and negatives are rejected. If you scale quantities to integers, interpret the result in that same scale.

Sources & references

External references open in a new tab. We are independent and not affiliated with these organizations.

  • Free
  • No sign-up
  • Runs entirely in your browser — nothing is uploaded.
  • Formula and method shown above

Provided “as is” for general information only — results may be inaccurate, so verify before you rely on them. No warranty; use at your own risk.

Built and reviewed by HIFreeTools against the formula shown above and any authoritative references cited on this page. See our methodology and editorial standards below.

Related tools

Embed this tool on your site

Free to embed, no sign-up. Paste this code where you want the tool to appear: