LCM and GCD Calculator
The greatest common divisor and the least common multiple are two of the most useful tools in number theory, and they show up constantly when you work with fractions, schedules and patterns. This calculator finds both for any pair of whole numbers. Enter two numbers and the tool computes the greatest common divisor (GCD), the largest number that divides both evenly, using Euclid's algorithm, then uses it to find the least common multiple (LCM), the smallest number both divide into. Euclid's algorithm is elegant and fast: it keeps replacing the larger number with the remainder of dividing it by the smaller until the remainder reaches zero, and the last nonzero value is the GCD. The LCM follows directly because the product of two numbers equals their GCD times their LCM, so the LCM is the product divided by the GCD. The GCD reduces fractions to lowest terms, while the LCM gives the least common denominator for adding fractions and tells you when two repeating cycles align again. Both inputs are editable, and the tool uses the whole-number absolute value of whatever you enter. Every figure is computed deterministically from the formulas shown below, with a worked example that reconciles exactly to the calculator's defaults.
The GCD comes from Euclid's algorithm and the LCM from LCM = (a x b) / GCD. For 12 and 18, the greatest common divisor is 6 and the least common multiple is 36.
GCD and LCM formulas
GCD(a, b) by Euclid: replace (a, b) with (b, a mod b) until b = 0; GCD is the last a
LCM(a, b) = ( a x b ) / GCD(a, b)
a, b = positive whole numbers
a mod b = remainder of a divided by b
Use Euclid's algorithm to find the GCD by taking remainders, then divide the product of the two numbers by the GCD to get the LCM.
Worked example
Find the GCD and LCM of 12 and 18.
- 18 mod 12 = 6, so replace (18, 12) with (12, 6)
- 12 mod 6 = 0, so the GCD is 6
- Product = 12 x 18 = 216
- LCM = 216 / 6 = 36
The GCD is 6 and the LCM is 36. These are the calculator's default inputs, so the result above matches the widget exactly.
GCD and LCM for sample pairs
Greatest common divisor and least common multiple for a few number pairs.
| a | b | GCD | LCM |
|---|---|---|---|
| 12 | 18 | 6 | 36 |
| 8 | 12 | 4 | 24 |
| 7 | 5 | 1 | 35 |
| 24 | 36 | 12 | 72 |
GCD times LCM always equals the product of the two numbers.
LCM and GCD calculator: frequently asked questions
What are the GCD and LCM?
The greatest common divisor (GCD), also called the greatest common factor, is the largest whole number that divides both numbers evenly. The least common multiple (LCM) is the smallest whole number that both numbers divide into evenly. For 12 and 18, the GCD is 6 and the LCM is 36. They are linked: GCD times LCM equals the product of the two numbers.
How does Euclid's algorithm find the GCD?
Euclid's algorithm repeatedly replaces the larger number with the remainder of dividing it by the smaller, until the remainder is zero. The last nonzero value is the GCD. For 18 and 12: 18 divided by 12 leaves 6; 12 divided by 6 leaves 0; so the GCD is 6. It is fast and works for any pair of whole numbers.
How is the LCM calculated from the GCD?
Once you have the GCD, the LCM is the product of the two numbers divided by the GCD: LCM = (a times b) divided by GCD. For 12 and 18, that is 12 times 18 = 216, divided by the GCD 6, giving 36. Dividing by the GCD first avoids overflow and keeps the result exact.
What are these used for?
The GCD simplifies fractions to lowest terms by dividing the numerator and denominator by their GCD. The LCM is the least common denominator when adding or subtracting fractions, and it solves problems about events that repeat on different cycles, such as when two recurring schedules line up again.
Do the numbers have to be whole?
Yes. The GCD and LCM are defined for positive whole numbers (integers). This calculator takes the absolute value and whole-number part of your inputs. For fractions or decimals, scale them to whole numbers first. The GCD of a number with zero is the number itself, and the LCM involving zero is defined as zero.
Official sources
- Number theory and arithmetic reference: US National Institute of Standards and Technology (NIST). As at 25 June 2026.
Reviewed by the CalculatorHub team, edited by James Graham, 25 June 2026. See our methodology. This is general information, not financial, tax, legal or investment advice.