🧮
🧮 Math & statistics

GCD & LCM Calculator

Results update as you type.

Your numbers

Understanding the GCD and LCM calculator — concept and principle

The greatest common divisor (GCD, also called the greatest common factor or HCF) is the largest whole number that divides every number in a list. The least common multiple (LCM) is the smallest positive number that every number in the list divides. The GCD is used to simplify fractions and split things into equal groups; the LCM is used for common denominators and for working out when repeating cycles line up, such as two buses that leave every 12 and 18 minutes.

Venn diagram of prime factors of 12, 18 and 30All three share 2 and 3, so the GCD is 6; multiplying every factor in the diagram, 2·2·3·3·5, gives the LCM 180.12, 18 and 30 as prime factors12 = 2·2·318 = 2·3·330 = 2·3·523235GCD = shared middle = 2 × 3 = 6LCM = every chip = 2·2·3·3·5 = 180
The overlap gives the GCD; the whole picture gives the LCM.

How it is calculated

Inputs are rounded to whole numbers.

The principle

Any number that divides both a and b also divides a − b, and therefore also the remainder a mod b. So the pair (a, b) and the pair (b, a mod b) have exactly the same common divisors, and the numbers shrink at every step until the answer appears. The LCM formula follows from prime factorizations: the GCD takes each prime to its lowest power, the LCM to its highest, and lowest + highest equals the sum of both exponents, so GCD × LCM = a × b.

Worked example

  1. Inputs: 12, 18, 30.
  2. GCD(12, 18): 18 = 1 × 12 + 6, then 12 = 2 × 6 + 0, so 6. Next GCD(6, 30) = 6. Result: GCD = 6.
  3. LCM(12, 18) = 216 ÷ 6 = 36.
  4. LCM(36, 30) = 1080 ÷ GCD(36, 30) = 1080 ÷ 6 = 180. Result: LCM = 180.
  5. Check with factorizations: 12 = 2²·3, 18 = 2·3², 30 = 2·3·5. Lowest powers give 2·3 = 6; highest powers give 2²·3²·5 = 180.

How to read the result

A GCD of 1 means the numbers are coprime: they share no factor and any fraction built from two of them is already in lowest terms. The LCM is always at least as large as the biggest input, and it equals the product of the numbers only when they are pairwise coprime. In the bus example, buses every 12 and 18 minutes leave together every 36 minutes.

Common mistakes

Keep in mind: Results above about 9 × 10¹⁵ exceed the exact integer range of standard double-precision numbers, so the LCM of many large inputs may not be exact.

Frequently asked questions

What is the GCD of a number and 0?

GCD(a, 0) = |a|, because every number divides 0. The LCM involving 0 is usually defined as 0.

How do I find the GCD of two large numbers by hand?

Use repeated division: divide the larger by the smaller, replace the larger with the remainder, and stop when the remainder is 0.

Are GCF, HCF and GCD the same thing?

Yes. They are regional names for the same quantity.

Sources: Euclid, Elements, Book VII, Propositions 1–3 and 34 · D. E. Knuth, The Art of Computer Programming, Vol. 2: Seminumerical Algorithms, Section 4.5.2

Checked 8 Nov 2026. Standard formulas, computed in your browser with double-precision numbers.

</> Add this calculator to your website (free)

Copy this code into your blog or site. It is free to use; please keep the credit link.

Preview
🧮 All math & statistics tools →🌍 Calculators by country →