HandyTools Hub

GCD & LCM Calculator

Calculate the Greatest Common Divisor and Least Common Multiple for multiple numbers

100% client-side processing

The GCD & LCM Calculator finds the greatest common divisor and least common multiple of a list of whole numbers and shows the reduction steps. It is the tool to reach for when simplifying a fraction, lining up repeating schedules, or checking a gear ratio, and it handles more than the usual pair of inputs.

How to Use

  1. Type two or more numbers, separated by commas or spaces. A mix such as 48, 18 and 48 18 both work.
  2. Read the two results: the GCD and the LCM.
  3. Open the steps panel to see each pairwise calculation in order.
  4. Copy either result with one click.

The parser splits on any run of commas or whitespace and ignores tokens that are not numbers, so stray separators, trailing commas, and pasted line breaks do not cause an error.

Worked Example: GCD(48, 18)

The GCD uses the Euclidean algorithm: divide the larger number by the smaller, replace the pair with the smaller number and the remainder, and repeat until the remainder is zero. The last non-zero remainder is the GCD.

48 ÷ 18 = 2 remainder 12
18 ÷ 12 = 1 remainder  6
12 ÷  6 = 2 remainder  0

The final non-zero remainder is 6, so GCD(48, 18) = 6. The tool’s step line for the pair is GCD(48, 18) = 6.

The LCM then follows from the identity below, giving 48 × 18 ÷ 6 = 144. As a check, both 48 and 18 divide evenly into 144, and no smaller number does.

Extending to Three or More Numbers

With more than two inputs, the calculation runs as a chain. For the list 12, 18, 24:

StepOperationResult
1GCD(12, 18)6
2GCD(6, 24)6
3LCM(12, 18)36
4LCM(36, 24)72

The overall GCD is 6 and the LCM is 72. Pairwise folding is valid because both gcd and lcm are associative and commutative over the positive integers, so the order of the inputs does not change the final answer.

The Formula Linking GCD and LCM

For any two positive integers a and b:

GCD(a, b) × LCM(a, b) = a × b

The tool uses the rearranged form to compute the LCM only after it has the GCD:

LCM(a, b) = (a × b) / GCD(a, b)

This is more efficient and less error-prone than factoring each number, and it explains why the LCM of a pair always divides evenly by the pair. The two quantities are inverses of each other: the GCD is the largest piece that fits into both numbers, the LCM the smallest container that both fill exactly.

For a list of numbers, the identity extends one pair at a time rather than holding as a single product, which is why the steps are shown pairwise.

Edge Cases and Limits

  • Decimals are rounded. Each input passes through Math.round, so 2.5 becomes 3 and 4.4 becomes 4. The displayed inputs in the result list are the rounded integers, not what you typed.
  • Zero forces the LCM to zero. GCD(0, 5) = 5, but LCM(0, 5) = 0. The step line reads LCM(0, 5) = 0 (contains zero).
  • Negative numbers use their magnitude. GCD(-12, 18) = 6 and LCM(-12, 18) = 36.
  • Large coprime inputs can overflow. With JavaScript’s double-precision numbers, the LCM is exact only up to about 9 quadrillion. A set like 999983, 999979, 999961 may exceed that range.
  • Non-numeric tokens are discarded. 12, abc, 18 silently becomes 12, 18, so check the parsed number list before trusting the result.

Reducing Fractions with the GCD

The most common use of the GCD is putting a fraction into lowest terms. Dividing both parts by their greatest common divisor reduces it in one step, because that divisor is by definition the largest factor the two share.

Take 48/18. The GCD is 6, so divide top and bottom: 48 ÷ 6 = 8 and 18 ÷ 6 = 3, giving 8/3. No smaller pair of integers represents the same value, and 8 and 3 are coprime, meaning their GCD is 1. Doing the same with a negative denominator is safe because the tool takes absolute values, so 48/-18 also reduces to -8/3 in sign convention terms.

The LCM is the counterpart for addition and subtraction. To add 1/12 and 1/18 you need a common denominator, and the smallest one is LCM(12, 18) = 36. Rewrite both fractions over 36: 1/12 = 3/36 and 1/18 = 2/36, so the sum is 5/36. Choosing the LCM keeps the numbers as small as possible; any common multiple would work, but 36 is the least.

For a chain of fractions, enter all the denominators at once and use the resulting LCM as the shared denominator. That is why the tool accepts a list rather than just a pair.

Where This Shows Up

  • Fraction simplification. Divide numerator and denominator by their GCD to reduce in one step: 48/18 becomes 8/3.
  • Scheduling. The LCM tells you when two repeating events next coincide. Every 12 days and every 18 days lines up again after 36 days.
  • Gear ratios and machines. The GCD gives the simplest tooth ratio; the LCM shows when two meshing gears return to their starting alignment.
  • Number theory practice. Seeing every Euclidean step makes the algorithm easier to reproduce by hand in an exam.

Frequently Asked Questions

Does the calculator accept decimal numbers?

It accepts them as input but rounds each value to the nearest whole number before calculating. Entering 4.6 and 9.2 is treated as 5 and 9, giving a GCD of 1 and an LCM of 45. If you need exact rational results, convert the decimals to fractions first.

What happens if I include zero in the list?

Zero is allowed. The GCD treats it as a value the other numbers divide, so gcd(0, 5) is 5. The LCM is different: any list containing zero returns an LCM of 0, because there is no positive multiple of zero. The steps output notes this explicitly.

How many numbers can I enter at once?

There is no fixed limit. The tool folds the calculation pairwise from left to right: it computes GCD(a, b), then GCD of that result with the third number, and so on. The same pairwise folding is used for the LCM, which works because both operations are associative over the integers.

Does a negative sign change the answer?

No. Every input is converted to its absolute value, so entering -12 and 18 gives the same GCD and LCM as 12 and 18: 6 and 36. This matters in fraction work, where a negative denominator is common and should not alter the reduction factor.

What do the step lines tell me?

Each line shows one pairwise reduction, for example GCD(48, 18) = 6 or LCM(36, 24) = 72. Reading them top to bottom retraces the Euclidean algorithm as the tool ran it, so the final line holds the overall answer.

Can the LCM become too large to be exact?

Yes. The LCM is computed with standard JavaScript numbers, which are safe up to 9,007,199,254,740,991. A handful of large, mutually coprime inputs can exceed that and lose precision silently. The GCD stays exact because it is always bounded by the smallest input.

Reviewed by the HandyTools Hub team · Last updated