GCD and LCM Calculator - Greatest Common Divisor and Least Common Multiple with Steps
Enter two or more whole numbers to get their greatest common divisor (GCD) and least common multiple (LCM).
Maintained by Hirantha Sandaruwan Lakshan. Updated 13 October 2026.
About this tool
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.
How it works
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 examples
48 and 180
180 = 3 × 48 + 36, then 48 = 1 × 36 + 12, then 36 = 3 × 12 + 0. The last non-zero remainder is 12, so the GCD is 12. The LCM is 48 ÷ 12 × 180 = 720.
Three numbers: 12, 18 and 24
gcd(12, 18) = 6 and then gcd(6, 24) = 6, so the GCD is 6. lcm(12, 18) = 36 and then lcm(36, 24) = 72, so the LCM is 72.
Adding 5/12 + 7/18
The common denominator is the LCM of 12 and 18, which is 36. 5/12 = 15/36 and 7/18 = 14/36, so the sum is 29/36.
Simplifying 84/126
The GCD of 84 and 126 is 42. Divide both by 42 to get 2/3, which is the fraction in lowest terms.
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 |
Frequently asked questions
What is the difference between GCD and LCM?
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.
Are GCD, HCF and GCF the same thing?
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.
How do I find the GCD of three or more numbers?
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.
What does it mean when the GCD is 1?
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.
Why does the calculator reject zero and negative numbers?
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.
How is the LCM used when adding fractions?
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.
How big can the numbers be?
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 & references
Updated Oct 13, 2026