Skip to content

GCF and LCM calculator

Greatest common factor, least common multiple and prime factors.

GCF

–

greatest common factor

LCM

–

least common multiple

    Working

      Shared primes

      Factor trees

      Whole numbers from 1 to 1,000,000,000, between two and six at a time. Separate them with commas or spaces.

      What are the GCF and LCM of two numbers?

      The greatest common factor (GCF, also called the greatest common divisor or highest common factor) is the largest whole number that divides every number in a set with no remainder. The least common multiple (LCM) is the smallest positive number that every number in the set divides into. For 12 and 18 the GCF is 6 and the LCM is 36.

      GCF is never larger than the smallest number you give it, and LCM is never smaller than the largest. If your answer breaks either rule, the two have been swapped.

      12 and 18 as overlapping prime factors
      12 18 2 2 3 3 overlap 2 × 3 = 6 (GCF) all four: 2 × 2 × 3 × 3 = 36 (LCM)

      12 = 2 × 2 × 3 and 18 = 2 × 3 × 3. Whatever sits in the overlap is common to both.

      Finding them with prime factors

      Every whole number above 1 breaks into prime factors in exactly one way (the fundamental theorem of arithmetic), so you can write each number as a product of primes and compare.

      1. Factor each number. Split it by its smallest prime until only primes are left. The factor trees in the calculator show this.
      2. For the GCF, take each prime that appears in every number, at its lowest power, and multiply.
      3. For the LCM, take each prime that appears in any number, at its highest power, and multiply.
      12, 18 and 30 side by side
      NumberPower of 2Power of 3Power of 5
      12 = 2² × 3 2 1 0
      18 = 2 × 3² 1 2 0
      30 = 2 × 3 × 5 1 1 1
      Lowest (GCF = 2 × 3 = 6) 1 1 0
      Highest (LCM = 4 × 9 × 5 = 180) 2 2 1

      Source: worked example; the calculator's prime grid shows this table for your numbers.

      Worked examples

      GCF and LCM of 48 and 180
      1. 48 = 2 × 2 × 2 × 2 × 3 = 2⁴ × 3.
      2. 180 = 2 × 2 × 3 × 3 × 5 = 2² × 3² × 5.
      3. GCF: lowest powers of the shared primes 2 and 3: 2² × 3 = 12.
      4. LCM: highest powers of 2, 3 and 5: 2⁴ × 3² × 5 = 720.
      5. Check: 12 × 720 = 8,640 and 48 × 180 = 8,640.
      Quick answers
      NumbersGCFLCM
      8, 12 4 24
      9, 15 3 45
      14, 21 7 42
      7, 13 (both prime) 1 91
      6, 8, 12 2 24
      10, 25, 40 5 200

      Source: calculated with this page's code.

      The fast way: Euclid’s algorithm

      Euclid’s method, from Book VII of the Elements (around 300 BC), finds the GCF without factoring: divide the larger number by the smaller, replace the larger with the remainder, and repeat until the remainder is 0. The last non-zero remainder is the GCF. For 180 and 48:

      Euclid's algorithm on 180 and 48
      StepDivisionRemainder
      1 180 = 3 × 48 + 36 36
      2 48 = 1 × 36 + 12 12
      3 36 = 3 × 12 + 0 0 (stop: GCF = 12)

      Source: Euclid, Elements, Book VII, Proposition 2.

      The LCM of two numbers is their product divided by the GCF: 48 × 180 ÷ 12 = 720. This only works two numbers at a time; for more, go in pairs: LCM(a, b, c) = LCM(LCM(a, b), c).

      Prime numbers under 100

      A prime has exactly two factors, 1 and itself, so 1 is not prime (counting it would break the one-way factoring rule), and 2 is the only even prime.

      The 25 primes below 100
      RangePrimesCount
      0 to 9 2, 3, 5, 7 4
      10 to 19 11, 13, 17, 19 4
      20 to 29 23, 29 2
      30 to 39 31, 37 2
      40 to 49 41, 43, 47 3
      50 to 59 53, 59 2
      60 to 69 61, 67 2
      70 to 79 71, 73, 79 3
      80 to 89 83, 89 2
      90 to 99 97 1

      Source: listed by this page's own primality test; compare OEIS A000040.

      To test a number by hand, you only need to try primes up to its square root. To check 97, try 2, 3, 5 and 7 (since 11² is already 121). None divides it, so it is prime.

      Divisibility rules

      These shortcuts spot small factors without dividing.

      Divisibility rules
      Divisible byRuleExample
      2 Last digit is even 3,478
      3 Digits add up to a multiple of 3 4,512 (4+5+1+2 = 12)
      4 Last two digits make a multiple of 4 3,716 (16)
      5 Ends in 0 or 5 1,985
      6 Divisible by both 2 and 3 714
      9 Digits add up to a multiple of 9 6,291 (6+2+9+1 = 18)
      11 Alternating digit sum is 0 or a multiple of 11 2,728 (2−7+2−8 = −11)

      Source: standard rules of number theory.

      Where GCF and LCM show up

      • Tiling and cutting. The largest square tile that fits a 12 ft by 18 ft floor without cutting is GCF(12, 18) = 6 ft on a side; the area calculator gives the floor area.
      • Timetables. Buses every 12 and 18 minutes leave together again after LCM(12, 18) = 36 minutes; the time calculator adds that to a clock time.
      • Fractions. Simplify with the GCF of the numerator and denominator. Add with the LCM of the denominators; see the fraction calculator.
      • Ratios. Dividing every term by the GCF reduces 12 : 18 : 30 to 2 : 3 : 5, as the ratio calculator does.

      Common mistakes

      • Using the product as the LCM. 4 × 6 = 24, but LCM(4, 6) = 12. The product is the LCM only when the numbers share no factor.
      • Taking the wrong power. A prime missing from one number counts as power 0 there, which is why 5 drops out of the GCF of 12, 18 and 30.
      • Stopping a list of multiples too soon. 8 and 12 first meet at 24, not 16.

      Common questions

      Are GCF, GCD and HCF the same thing?

      Yes: three names for one number, used in different countries and textbooks.

      How do you find the GCF of three numbers?

      Find the GCF of the first two, then the GCF of that answer and the third. For 12, 18 and 30: GCF(12, 18) = 6, then GCF(6, 30) = 6.

      What is the GCF of two prime numbers?

      1, and their LCM is their product. The same holds for any coprime pair, such as 8 and 15 (GCF 1, LCM 120).

      Is 0 allowed?

      The calculator takes whole numbers from 1 up. An LCM including 0 would be 0, which is rarely what a problem wants.

      Sources

      Last reviewed November 9, 2026. Factoring happens locally in the tab, with nothing sent to a server.