GCD and LCM Calculator
Enter two or more positive whole numbers and get the greatest common divisor (also called the highest common factor) and the lowest common multiple. The page shows the Euclidean algorithm reductions, the prime factorisation of every input, and how the GCD and LCM fall out of those factorisations.
Explain like I'm 5 (what even is this calculator?)
The GCD is the biggest number that divides every one of your numbers with nothing left over. The LCM is the smallest number that every one of your numbers divides into cleanly. Useful for simplifying fractions (GCD) and for working out when repeating events line up again (LCM).
Calculate
Browser-only. The numbers you type are processed in your browser. Nothing is uploaded.
Enter at least two whole numbers and press Calculate.
Prove it
Methods: Euclidean algorithm for the GCD (gcd(a, b) = gcd(b, a mod b), recurse to b = 0). Prime factorisation by trial division up to the square root of each input. LCM derived two ways, as a cross-check: (a) by the identity LCM(a, b) = a × b / GCD(a, b), reduced pairwise for three or more inputs; (b) by taking the highest power of every prime that appears in any input's factorisation.
Useful? Save this calculator: press Ctrl + D to bookmark it.
Where GCD and LCM actually come up
This is one of those topics that looks like a textbook exercise and turns out to be quietly useful. Once you spot the pattern, you see it in fraction simplification, scheduling, gear ratios, music theory, engineering tolerances and any problem where two cycles need to line up.
Simplifying fractions: the GCD job
To reduce a fraction to its lowest terms, divide the top and the bottom by their GCD. 18 over 24 has GCD 6, so it simplifies to 3 over 4. 462 over 1,071 looks ugly until you find GCD 21 and reduce to 22 over 51. The Euclidean algorithm is the fastest way to do this by hand, and it is exactly what this page runs: keep replacing the larger number with the remainder when it is divided by the smaller, until the remainder reaches zero. The last non-zero divisor is the GCD.
Scheduling repeating events: the LCM job
If bus A leaves every 12 minutes and bus B every 18 minutes, both buses arrive together every LCM(12, 18) = 36 minutes. If three machines need servicing every 4, 6 and 8 weeks, they all need servicing in the same week every LCM(4, 6, 8) = 24 weeks. This kind of "when do they line up again" question is the LCM in disguise. So is the classic gear-ratio puzzle: a 14-tooth gear meshing with a 21-tooth gear returns to the same alignment every LCM(14, 21) = 42 teeth, which is 3 turns of the small gear and 2 of the large.
Music, ratios and engineering tolerances
In just intonation, two notes whose frequencies are in a small whole-number ratio sound consonant. Reducing those ratios to lowest terms is GCD work. The "beat frequency" between two slightly different pitches is a related calculation, and it explains why a piano in equal temperament is a careful approximation of these clean ratios rather than the clean ratios themselves.
In engineering, when you stack components with periodic features (threads, splines, bearing balls), the LCM of their periods tells you when a misalignment recurs. That feeds into vibration analysis and into how you pick tolerances so faults do not align catastrophically.
Two ways to find an LCM, and why we show both
The standard identity, LCM(a, b) = a × b / GCD(a, b), is the fastest method by hand. It also tells you something useful: the bigger the GCD, the smaller the LCM relative to the product. Coprime numbers (GCD 1) have the largest possible LCM, equal to the product itself. Numbers where one divides the other (GCD equal to the smaller value) have the smallest LCM, equal to the larger value. Everything else sits between those extremes.
The factorisation method generalises more cleanly. Write each input as a product of primes. The GCD takes the lowest power of every prime that appears in every input. The LCM takes the highest power of every prime that appears in any input. For 12 = 2² × 3 and 18 = 2 × 3², the GCD takes 2¹ × 3¹ = 6 and the LCM takes 2² × 3² = 36. The page shows both methods so the answer is auditable from two angles.
Common mistakes worth avoiding
Forgetting that LCM is not the product. LCM(4, 6) is 12, not 24. The product is an upper bound, equal to the LCM only when the inputs are coprime.
Mixing up GCD and LCM in fraction work. Use the GCD to reduce a single fraction. Use the LCM to find a common denominator when adding or subtracting two fractions. They are different jobs.
Trying to factorise everything by inspection. Trial division is reliable for the sizes that come up in school work, but for large numbers it is slow. The Euclidean algorithm sidesteps factorisation entirely for finding a GCD, which is why it is the better hand method when the numbers get awkward.
Edge cases the calculator handles
Two coprime numbers (no common factor beyond 1) give GCD 1 and LCM equal to their product. One number that divides the other gives GCD equal to the smaller and LCM equal to the larger. All identical numbers give both GCD and LCM equal to that single value. Large primes, like 999983 and 999979, are coprime and factorise to themselves. Powers of two give clean factorisations and tidy GCDs. The page rejects single inputs, decimals, zero and negatives with a clear message rather than guessing what you meant.
Related calculators
GCD and LCM underpin fraction work. These are the neighbouring tools.
Frequently asked questions
What is the difference between GCD and HCF?
Nothing. GCD (greatest common divisor) and HCF (highest common factor) are two names for exactly the same idea: the largest whole number that divides every number in your list with no remainder. UK schools tend to use HCF, US textbooks and most software libraries use GCD. The number you get back is identical.
How is LCM related to GCD?
For two numbers, LCM(a, b) equals (a multiplied by b) divided by GCD(a, b). The two numbers always carry the same total prime power between them, so what the GCD pulls out as shared, the LCM has to put back as the maximum on each side. For three or more numbers, the same identity does not hold directly, but you can still compute LCM pairwise: LCM(a, b, c) is LCM(LCM(a, b), c).
Why does this calculator reject zero and negative numbers?
GCD and LCM are normally defined for positive integers. GCD(0, n) is sometimes given as n in advanced texts, but in classroom use zero breaks the LCM (0 times anything is 0). Negatives are usually handled by taking absolute values, which would just hide a typo. To keep the working honest, the page asks for positive whole numbers and flags anything else.
How big a number can it factorise?
Up to one trillion (1012). Trial division up to the square root of the input runs in well under a second at that size in modern browsers. If you need to factorise something larger, a desktop CAS like SageMath or a dedicated number-theory library is the right tool.
Does the page send my numbers anywhere?
No. All the maths runs in your browser using vanilla JavaScript. The numbers you type never leave your device, and you can disconnect from the network and the page still works.