GCF & LCM Calculator
Enter two to ten whole numbers and get their greatest common factor (GCF) and least common multiple (LCM) at once, with the working shown three ways. GCF, GCD (greatest common divisor) and HCF (highest common factor) are three names for the same number, so this calculator answers all of those searches.
Your numbers
Try an example
Calculations run locally in your browser using exact big-integer arithmetic. Nothing you enter is sent anywhere.
Working, step by step
How to use the GCF & LCM calculator
- Type two to ten whole numbers into the box, separated by commas or spaces, for example
12, 18, 30. You can also tap one of the example buttons. - Read the GCF and the LCM, which update as you type. The copy buttons copy plain digits.
- For exactly two numbers the page also shows the identity GCF × LCM = a × b with your numbers filled in.
- Open a tab under “Working, step by step” to see the same answer by prime factorization, by the Euclidean algorithm or by listing factors. Prime factorization is offered for numbers up to 1,000,000,000,000 and listing for numbers up to 1,000,000. The Euclidean algorithm has no such limit, and it also handles 0.
What the GCF and the LCM are
The greatest common factor of several numbers is the largest whole number that divides every one of them with no remainder. The least common multiple is the smallest positive number that every one of them divides into with no remainder.
Cutting is a GCF problem. Say you have a 12 cm strip and an 18 cm strip and want to cut both into equal pieces with nothing left over. The longest possible piece is GCF(12, 18) = 6 cm. Repeating events are an LCM problem. If a bus leaves every 12 minutes and a train every 18 minutes and both leave at 9:00, they next leave together after LCM(12, 18) = 36 minutes, at 9:36.
How it works: three methods on one example
Here are all three methods for 12 and 18. The tool shows the same steps for any input.
1. Prime factorization. Write each number as a product of prime powers:
12 = 2² × 3 and 18 = 2 × 3². For the GCF take
every prime that appears in all the numbers, each with its smallest exponent:
2 × 3 = 6. For the LCM take every prime that appears in any number, each with
its largest exponent: 2² × 3² = 36.
2. Euclidean algorithm. Divide the larger number by the smaller one, then
replace the pair by the smaller number and the remainder, and repeat until the remainder is 0.
Here 18 = 1 × 12 + 6 and 12 = 2 × 6 + 0. The last non-zero
remainder, 6, is the GCF. It works because GCF(a, b) = GCF(b, r), where r is the remainder of a ÷ b. The LCM then follows from a × b ÷ GCF =
12 × 18 ÷ 6 = 36. For more than two numbers the tool chains the steps, as described in the FAQ below.
3. Listing. Factors of 12: 1, 2, 3, 4, 6, 12. Factors of 18: 1, 2, 3, 6, 9, 18. The common factors are 1, 2, 3 and 6, and the greatest is 6. Multiples of 12: 12, 24, 36. Multiples of 18: 18, 36. The first multiple they share is 36.
Which method to use
- Listing is the easiest to understand and fine for small numbers. It gets long for numbers in the thousands.
- Prime factorization suits medium numbers and several numbers at once, because the exponents are compared side by side. Factoring large numbers by hand is slow.
- The Euclidean algorithm is the fastest and needs no factoring. It takes at most about five divisions per digit of the smaller number.
Examples
Example 1: 48 and 180. 48 = 2⁴ × 3 and
180 = 2² × 3² × 5. GCF = 2² × 3 = 12.
LCM = 2⁴ × 3² × 5 = 720. Check: 12 × 720 = 8,640 = 48 × 180.
Example 2: 8, 12 and 20. GCF(8, 12) = 4, then GCF(4, 20) = 4, so the GCF is 4. LCM(8, 12) = 24, then LCM(24, 20) = 24 × 20 ÷ 4 = 120, so the LCM is 120.
Example 3: 1071 and 462. 1071 = 2 × 462 + 147,
462 = 3 × 147 + 21, 147 = 7 × 21 + 0. The GCF is 21 and the
LCM is 1071 × 462 ÷ 21 = 23,562.
Example 4: 17 and 31. Both are prime, so the GCF is 1, the numbers are coprime, and the LCM is their product, 527.
The link between GCF and LCM
For exactly two positive numbers, GCF(a, b) × LCM(a, b) = a × b. Here
a and b are the two numbers. With 12 and 18: 6 × 36 = 216 = 12 × 18. So
LCM = a ÷ GCF × b. The
identity does not extend to three or more numbers: for 8, 12 and 20 the product of the GCF and
LCM is 4 × 120 = 480, but 8 × 12 × 20 = 1,920.
Using the GCF and LCM with fractions
To simplify a fraction, divide the top and bottom by their GCF. For 48/180 the GCF is 12, so 48/180 = 4/15. To add fractions, use the LCM of the denominators as the common denominator. For 5/12 + 7/18 the LCM of 12 and 18 is 36, so 5/12 = 15/36 and 7/18 = 14/36, and the sum is 29/36.
Coprime numbers, 0 and 1
Numbers are coprime (or relatively prime) when their GCF is 1. They do not have to be prime themselves: 8 and 15 are coprime. Coprime numbers have an LCM equal to their product. For three or more numbers, a GCF of 1 does not mean every pair is coprime: 6, 10 and 15 have GCF 1, yet each pair shares a factor. The tool tells you when that happens.
The number 1 has only itself as a factor, so GCF(1, n) = 1 and LCM(1, n) = n. Every number divides 0, so GCF(0, n) = n. The only multiple of 0 is 0, so any LCM that includes 0 is 0. GCF(0, 0) has no greatest value, and the tool shows 0 with a note.
Frequently asked questions
Are GCF, GCD and HCF the same thing?
Yes. They are different names for the largest number that divides all the given numbers. “GCF” is common in United States schools, “HCF” in the United Kingdom and India, and “GCD” in higher mathematics and programming.
Can the GCF be larger than the numbers?
Not for positive numbers. The GCF divides every number, so it cannot exceed the smallest one. It equals the smallest number when that number divides all the others, as in GCF(6, 18) = 6. The LCM is the opposite: it is at least as large as the largest number.
How do I find the GCF of more than two numbers?
Find the GCF of the first two, then the GCF of that result with the third, and continue. The same chaining works for the LCM.
What happens with negative numbers, decimals and big numbers?
Negative numbers are replaced by their absolute value, because divisibility ignores the sign. Decimals are not accepted, since GCF and LCM are defined for whole numbers. Numbers of up to 30 digits are calculated exactly, with no rounding.
Is my data private?
Yes. Everything is calculated in your browser and nothing you type is uploaded. Your last input is kept only in your own browser storage.
Related tools
- Permutation & Combination Calculator — count arrangements and selections with exact big numbers.
- Percentage Calculator — percent of, percent change and reverse percentages.
- Quadratic Equation Solver — solve equations of the form ax² + bx + c = 0 step by step.
- Significant Figures Calculator — count and round significant figures.
- Unit Converter — convert length, mass and temperature units.