GCD and LCM Calculator Free | With Steps Shown Online

🔢 Math & Numbers Free Forever

GCD and LCM Calculator with Step-by-Step Work

Find the greatest common divisor and least common multiple of two or more numbers, with the Euclidean algorithm steps shown for full transparency.

Numbers (2 or more, comma or space separated)Whole numbers only. Enter at least two values.
About This Tool

How this calculator finds GCD and LCM using an algorithm older than most numeral systems

The greatest common divisor and least common multiple sound like grade school topics, but the method this tool uses to find them, the Euclidean algorithm, was written down by Euclid around 300 BC and is still considered one of the oldest algorithms in continuous use today. It needs no factoring, no prime lists, and no guessing. It just repeatedly divides and keeps the remainder until nothing is left to divide.

The tool works entirely in your browser and uses JavaScript’s BigInt type for the arithmetic, which means it stays exact even for numbers far larger than JavaScript’s normal floating point limit would handle safely. Nothing you enter leaves your device.

The Euclidean algorithm, step by step

Step 1 Divide the larger by the smaller Take the two numbers a and b, with a larger. Divide a by b and note both the quotient and the remainder: a = b × q + r.
Step 2 Replace and repeat Set a to the old value of b, and b to the remainder r. Run the division again.
Step 3 Stop at a zero remainder Keep going until the remainder hits exactly 0. Whatever value b holds at that final step is the GCD, since it is the last number that divided cleanly into everything before it.
Step 4 Derive the LCM from the GCD The least common multiple does not need its own algorithm. Once the GCD is known, LCM(a, b) = (a ÷ GCD) × b. Dividing before multiplying keeps the intermediate values smaller and avoids unnecessary overflow.
// the Euclidean algorithm with a recorded step trace function gcdWithSteps(a, b) { var steps = []; while (b !== 0n) { var q = a / b; var r = a % b; steps.push({ a: a, b: b, q: q, r: r }); a = b; b = r; } return { gcd: a, steps: steps }; } // LCM built from the GCD, dividing first to keep numbers small function lcmPair(a, b) { var g = gcdSimple(a, b); return (a / g) * b; }

The tool shows this exact trace on screen when you enter two numbers, one line per division step, so you can follow the algorithm collapsing toward the answer instead of just reading a final number.

Worked example: GCD and LCM of 48 and 180. 180 = 48 × 3 + 36. Then 48 = 36 × 1 + 12. Then 36 = 12 × 3 + 0. The remainder hit zero, so the GCD is 12, the last non-zero remainder. For the LCM, divide 48 by 12 to get 4, then multiply by 180: 4 × 180 = 720. Check it yourself: 720 ÷ 48 = 15 exactly, and 720 ÷ 180 = 4 exactly, confirming 720 is a common multiple, and no smaller number satisfies both.
StepDivision performedRemainder
1180 ÷ 48 = 336
248 ÷ 36 = 112
336 ÷ 12 = 30 (stop)

Extending to more than two numbers

GCD and LCM are technically pairwise operations, but the algorithm extends cleanly to a whole list. For three or more numbers, the tool folds the list left to right: GCD(a, b, c) is computed as GCD(GCD(a, b), c), and the same pattern applies to LCM. This works because GCD and LCM are both associative operations, the grouping does not change the final answer, only the order the calculation is written out in.

Exact BigInt arithmetic

Standard JavaScript numbers lose precision above 2 to the power 53. This tool uses BigInt throughout, so GCD and LCM stay exact even for numbers with a dozen or more digits.

Sign handling

Negative inputs are converted to their absolute value before the algorithm runs, since GCD and LCM are conventionally defined over positive integers regardless of the sign of the inputs.

2,300+ year old algorithm Zero not allowed as input Works pairwise across any list length

Problems these two solve

Reducing a fraction to lowest terms, finding a common denominator when adding fractions by hand, scheduling recurring events that need to align, like two machines that cycle every 18 and 24 minutes and you want to know when they next line up, splitting a design or grid layout into equal tiles without leftover space, and cryptography courses where the Euclidean algorithm is the starting point for the extended version used in RSA key generation. Any time two repeating cycles or two quantities need a common measure, GCD and LCM are the tools for the job.

Common Questions

FAQ: GCD and LCM Calculator

The GCD (greatest common divisor) is the largest number that divides evenly into all your numbers, useful for simplifying fractions, while the LCM (least common multiple) is the smallest number that all your numbers divide into evenly, useful for finding a common denominator or figuring out when repeating events align. They answer opposite kinds of questions: ‘what’s the biggest shared factor’ versus ‘what’s the smallest shared multiple.’

It repeatedly replaces the larger of two numbers with the remainder of dividing it by the smaller one, shrinking the pair each time, until the remainder reaches zero. The last non-zero remainder before hitting zero is the GCD, this works because any number that divides both original numbers must also divide their difference (and therefore their remainder), so the GCD is preserved at every step.

This identity holds because the product of two numbers can always be split into their shared factors (counted once, contributing to the GCD) and their remaining unique factors (which combine with the GCD to form the LCM). Rearranging the identity gives the formula this tool uses: LCM(a,b) = (a × b) ÷ GCD(a,b), which is far faster than listing out multiples until you find a match.

Apply the same two-number operation repeatedly: first find GCD(a, b), then find the GCD of that result with c, and so on down your list, the same logic applies to LCM. This works because both GCD and LCM are associative operations, meaning the order you combine numbers in doesn’t change the final answer.

Dividing both the numerator and denominator of a fraction by their GCD produces the simplest possible equivalent fraction, for example, 48/180 simplifies to 4/15 by dividing both by their GCD of 12. Any fraction can be fully simplified in exactly one division step once you know the GCD, rather than repeatedly dividing by small trial factors.

By convention, GCD and LCM are typically defined using the absolute (positive) values of the numbers involved, since divisibility and multiples work the same regardless of sign, this tool follows that convention and treats -12 the same as 12 for these calculations. Zero is excluded entirely, since every number divides into zero, making its GCD and LCM mathematically undefined in the usual sense.

Privacy Overview

Cookies let this site remember your preferences and show us which tools people actually use. Full detail sits in our Privacy Policy.