Formula
HCF(a, b) = HCF(b, a mod b) (Euclid)LCM(a, b) = a × b ÷ HCF(a, b)
- For more than two numbers, combine them pairwise.
The HCF is the largest number that divides all of them; the LCM is the smallest number they all divide.
Worked example
12, 18 and 24
- Whole numbers
- 12 18 24
HCF (GCD)
6
LCM: 72
How it works
Euclid's algorithm finds the HCF by repeatedly replacing the larger number with the remainder after dividing. HCF(48, 18): 48 mod 18 = 12, 18 mod 12 = 6, 12 mod 6 = 0, so the HCF is 6. The LCM follows from LCM = a × b ÷ HCF = 48 × 18 ÷ 6 = 144.
The table shows each number's prime factorisation, which is the method taught in school: the HCF takes the lowest power of each shared prime, the LCM takes the highest power of every prime. Big numbers are handled exactly with integer arithmetic.
The LCM is what you need to add fractions with different denominators — see Fraction Calculator — and the HCF is what simplifies a ratio in Ratio Calculator.
Assumptions and limits
- Only positive whole numbers are accepted.
- Co-prime numbers (HCF 1) are flagged in a note.