# GCD and LCM Calculator - Greatest Common Divisor and Least Common Multiple with Steps

Page: https://hirantha.me/tools/gcd-lcm-calculator
Part of: Hirantha Sandaruwan Lakshan free tools (https://hirantha.me/tools)
Updated: 2026-10-13

Find the greatest common divisor and least common multiple of two or more whole numbers, with the Euclidean steps and prime factors shown.

This is a free tool that runs in the browser: open the page to use it. File tools process files on the visitor's own device; files are never uploaded or stored. No account, sign-up, payment or watermark.

Enter two or more whole numbers to get their greatest common divisor (GCD) and least common multiple (LCM). For two numbers the page lays out Euclid's algorithm line by line, and for numbers up to a trillion it also shows the prime factorisation method. The GCD is also called the highest common factor (HCF) or greatest common factor (GCF). Results are exact for numbers of up to 100 digits, and nothing leaves your browser.

The GCD of some numbers is the largest whole number that divides all of them with no remainder. The LCM is the smallest positive number that all of them divide into. For 12 and 18 the GCD is 6 and the LCM is 36.

Euclid's algorithm finds the GCD without factorising anything. Divide the larger number by the smaller, then divide the smaller by the remainder, and repeat until the remainder is 0. The last non-zero remainder is the GCD. It appears in Book VII of Euclid's Elements and is still the standard method. It is quick: the number of divisions never exceeds five times the number of digits of the smaller number (Lamé's theorem).

The prime factorisation method writes each number as a product of primes. The GCD takes each shared prime to its lowest power, and the LCM takes every prime to its highest power. For 48 = 2^4 × 3 and 180 = 2^2 × 3^2 × 5, the GCD is 2^2 × 3 = 12 and the LCM is 2^4 × 3^2 × 5 = 720.

For two numbers, GCD × LCM = a × b, so LCM = a ÷ GCD × b. For a longer list, take the GCD (or LCM) of the first two numbers, then of that result and the third, and so on; the order does not change the answer. Numbers whose GCD is 1 are called coprime.

Zero is not accepted. By the usual convention gcd(0, n) = n and lcm(0, n) = 0, but a zero in a list is almost always a typing slip, so the calculator asks for positive whole numbers. Negative numbers and decimals are refused with a message that says why.

Worked pairs:
| Numbers | GCD | LCM | Prime factorisations |
| --- | --- | --- | --- |
| 12 and 18 | 6 | 36 | 12 = 2^2 × 3, 18 = 2 × 3^2 |
| 48 and 180 | 12 | 720 | 48 = 2^4 × 3, 180 = 2^2 × 3^2 × 5 |
| 54 and 24 | 6 | 216 | 54 = 2 × 3^3, 24 = 2^3 × 3 |
| 100 and 75 | 25 | 300 | 100 = 2^2 × 5^2, 75 = 3 × 5^2 |
| 84 and 126 | 42 | 252 | 84 = 2^2 × 3 × 7, 126 = 2 × 3^2 × 7 |
| 17 and 5 | 1 | 85 | Both are prime, so they are coprime |

Q: What is the difference between GCD and LCM?
A: The GCD is the largest number that divides all your numbers, so it is never bigger than the smallest of them. The LCM is the smallest number that all of them divide into, so it is never smaller than the largest. For 4 and 6 the GCD is 2 and the LCM is 12.

Q: Are GCD, HCF and GCF the same thing?
A: Yes. Greatest common divisor, highest common factor and greatest common factor all name the same number. LCM is also written as the lowest common multiple.

Q: How do I find the GCD of three or more numbers?
A: Find the GCD of the first two, then the GCD of that answer and the third number, and carry on down the list. The order does not change the result. This page shows the Euclid steps for each pair.

Q: What does it mean when the GCD is 1?
A: The numbers are coprime: they share no factor except 1. The LCM of two coprime numbers is simply their product, such as 5 × 17 = 85. A fraction whose top and bottom are coprime is already in lowest terms.

Q: Why does the calculator reject zero and negative numbers?
A: By convention gcd(0, n) = n and lcm(0, n) = 0, so a zero in a list would force the LCM to 0, and it is usually a typing slip. The tool asks for positive whole numbers. For a negative number use its size without the minus sign, because the GCD and LCM do not depend on the sign.

Q: How is the LCM used when adding fractions?
A: The least common denominator of two fractions is the LCM of their denominators. For 1/6 + 1/4 the LCM of 6 and 4 is 12, so you add 2/12 and 3/12 to get 5/12.

Q: How big can the numbers be?
A: Each number can have up to 100 digits and you can enter up to 30 numbers. The arithmetic is exact. The prime factorisation view is shown only when every number is at most 1,000,000,000,000, because factorising bigger numbers by trial division is slow; the Euclidean algorithm has no such limit.

Sources: Euclid's Elements, Book VII, Proposition 2: finding the greatest common measure (https://mathcs.clarku.edu/~djoyce/elements/bookVII/propVII2.html); Greatest common divisor - Wikipedia (https://en.wikipedia.org/wiki/Greatest_common_divisor); Least common multiple - Wikipedia (https://en.wikipedia.org/wiki/Least_common_multiple); Euclidean algorithm - Wikipedia (https://en.wikipedia.org/wiki/Euclidean_algorithm)

Related tools:

- [Fraction calculator](https://hirantha.me/tools/fraction-calculator.md): Add, subtract, multiply and divide fractions and mixed numbers, with the working shown, the answer in lowest terms and as a decimal.
- [Prime number checker](https://hirantha.me/tools/prime-number-checker.md): Check whether a number is prime, up to 2^64, see its prime factors and the previous and next prime, and list every prime up to 100,000.
- [Ratio calculator](https://hirantha.me/tools/ratio-calculator.md): Simplify a ratio, scale it to a new value, divide an amount in a ratio such as Rs. 10,000 in 3:2, or turn a ratio into percentages.
- [Number base converter](https://hirantha.me/tools/number-base-converter.md): Convert whole numbers between binary, octal, decimal, hex and any base from 2 to 36 with exact BigInt maths, negatives, two's complement and step-by-step working.
- [Quadratic equation solver](https://hirantha.me/tools/quadratic-equation-solver.md): Solve ax² + bx + c = 0: real or complex roots, discriminant, vertex, axis of symmetry and factored form, with the working shown.
