GCF Calculator - With Prime Factorization

Use this GCF calculator to find the greatest common factor of two integers. See each prime factorization, the LCM, the Euclidean step count, and a coprime flag.

Updated: June 16, 2026 • Free Tool

GCF Calculator

Enter any whole number from 1 to 1,000,000,000,000. Negative entries are read as their absolute value.

Enter a second whole number from 1 to 1,000,000,000,000. The calculator returns the largest integer that divides both entries exactly; negative values become their absolute value.

Results

Greatest Common Factor
0
Least Common Multiple 0
Euclidean Step Count 0
Coprime (1 = yes) 0
Prime Factorization of a 0
Prime Factorization of b 0

What Is GCF Calculator?

A GCF calculator is a number-theory tool that finds the largest positive integer dividing two whole numbers exactly. It is the everyday companion to fraction simplification, ratio reduction, and the modular-arithmetic identities used in cryptography. The default example returns a GCF of 6 because 6 is the largest number that fits into both 48 and 18 without a remainder, and the result panel reports the LCM, the Euclidean step count, a coprime flag, and the prime factorization of each input.

  • Simplifying fractions to lowest terms: Divide the numerator and denominator by the GCF. The fraction 48/18 reduces to 8/3 once the GCF of 6 is removed.
  • Reducing mechanical ratios and recipes: Cut a gear ratio like 36:84 to 3:7 by dividing both terms by the GCF of 12, so the parts list is easier to read.
  • Scheduling cycles and tiling patterns: Pair the GCF with the LCM to plan a cycle that fits an exact number of repeats, such as a 24 by 30 tile grid.

The math behind this tool is small enough to do by hand for tiny inputs, but the moment the numbers get large the Euclidean algorithm or a prime factorization table saves a lot of trial division. Both inputs are read as positive whole numbers, and the GCF is the gateway to the LCM through the identity a * b = GCF * LCM.

A GCD page presents the same number under a different name, so the GCF and GCD results are interchangeable once the Euclidean algorithm has finished.

The dedicated GCD calculator follows the same identity but emphasizes the Euclidean algorithm and the LCM in its result panel, so it suits users who only need the GCD/LCM pair and do not need the prime-factor breakdown that this page shows side by side.

How GCF Calculator Works

The tool uses the Euclidean algorithm to find the greatest common factor in a small number of remainder steps and reports the prime factorization of each input as a sanity check. Both methods return the same number, so the result panel stays consistent regardless of which approach the user wants to verify.

gcf(a, b) = gcf(b, a mod b) while b != 0; the last non-zero remainder is the GCF.\nEquivalent prime-factor form: gcf(a, b) = product of every prime that appears in both factorizations, raised to the smaller exponent.
  • a, b: The two positive integer inputs. Negative values are taken as their absolute value before the Euclidean loop runs, and both must be in the range 1 to 1,000,000,000,000.
  • gcf: The greatest common factor, returned as the last non-zero remainder of the Euclidean algorithm.
  • lcm: The least common multiple, computed as floor(a / gcf) * b so the division happens before the multiplication, then clamped to Number.MAX_SAFE_INTEGER whenever the exact product would lose precision in a JavaScript double.

The worked example agrees with the standard table of Euclidean examples cited in the academic literature on the algorithm.

Worked example: GCF of 48 and 18 (the standard textbook case)

a = 48, b = 18.

1. 48 mod 18 = 12, so the next pair is (18, 12).\n2. 18 mod 12 = 6, so the next pair is (12, 6).\n3. 12 mod 6 = 0, so the loop terminates and the last non-zero remainder is 6.\n4. The LCM is 48 * 18 / 6 = 144, and 48 = 2^4 x 3, 18 = 2 x 3^2 share 2 and 3 at the smaller exponents 1 and 1, so the prime-factor product is 2 * 3 = 6.

GCF = 6, LCM = 144, Euclidean step count = 3, coprime flag = 0. Prime factorization: 48 = 2^4 x 3, 18 = 2 x 3^2.

The fraction 48/18 reduces to 8/3 once the GCF is divided out, and the same three-step Euclidean trace works for any pair of small whole numbers.

According to Wolfram MathWorld, the Euclidean algorithm finds the greatest common divisor of two integers by repeatedly replacing the larger number with the remainder of dividing it by the smaller, and it terminates when the smaller number becomes zero.

When the result is meant to simplify a fraction like 48/18 going to 8/3, the fraction calculator performs the same reduction as a single step without retyping the inputs, so the GCF result from this page can be carried into fraction arithmetic without copying the number out by hand.

Key Concepts Explained

Four short ideas explain every value the result panel shows and how the GCF connects to elementary number theory.

GCF, GCD, and HCF Are the Same Number

Greatest common factor, greatest common divisor, and highest common factor are three names for the same integer.

Prime Factorization Method

Breaking each number into its prime factors, then multiplying every prime that appears in both lists at the smaller exponent, gives the GCF.

Euclidean Algorithm

Replace the larger number with the remainder of dividing it by the smaller, and repeat until the remainder is 0. The last non-zero remainder is the GCF.

Coprime Numbers

Two integers are coprime when their only positive common factor is 1, which is the same as saying the GCF equals 1. The coprime flag in the panel is 1 for coprime pairs and 0 otherwise.

These concepts also connect to related tools on the site. The remainder step at the heart of the Euclidean algorithm is the same operation a modulo calculator reports for any pair of integers, which is why the GCF and the modulo operator show up together in number-theory references.

The modulo calculator builds on the GCF in the opposite direction by reporting the remainder of integer division, and that GCF-modulo pairing is the foundation of the extended Euclidean algorithm used to find modular inverses in modular arithmetic.

How to Use This Calculator

Five quick steps take you from any pair of integers to a verified result, a prime factorization check, and the matching LCM.

  1. 1 Enter the first integer: Type the first whole number into the 'First Number (a)' field. The default is 48, but any whole number from 1 to 1,000,000,000,000 is accepted, and negative entries are read as their absolute value.
  2. 2 Enter the second integer: Type the second whole number into the 'Second Number (b)' field. The default is 18, and the same absolute-value rule applies to negatives.
  3. 3 Read the GCF in the top result card: The primary 'Greatest Common Factor' card shows the integer that divides both inputs exactly. The number is exact, so there is no rounding.
  4. 4 Verify against the prime factorizations: Look at the two factorization rows. The primes that appear in both rows, raised to the smaller exponent, multiply together to give the GCF. This is the prime-factor method check.
  5. 5 Use the LCM, step count, and coprime flag downstream: The LCM is the smallest common multiple of the two inputs, the Euclidean step count is the number of remainder divisions, and the coprime flag is 1 only when the GCF equals 1.

To reduce the fraction 84/56, enter 84 as a and 56 as b. The result is 28, the LCM is 168, and the prime factorizations shown in the panel are 84 = 2^2 x 3 x 7 and 56 = 2^3 x 7. The shared primes 2 and 7, taken at the smaller exponents 2 and 1, multiply to 28, and dividing both 84 and 56 by 28 reaches 3/2 in simplest form.

When the numerator and denominator are already paired and the user only needs the simplest form, the dedicated simplify fractions calculator takes a fraction like 84/56 and returns 3/2 in a single step, with the GCF reduction built in for any pair of positive integers.

Benefits of Using This Calculator

A purpose-built gcf calculator removes the trial division that comes with finding the largest shared factor by hand.

  • Verifies the GCF two ways at once: The Euclidean step count and the prime factorization rows give independent confirmations of the same number.
  • Reports the LCM in the same panel: Using the identity a * b = GCF * LCM, the LCM is shown next to the result so cycle and scheduling problems do not need a second tool.
  • Highlights coprime pairs in one glance: The coprime flag returns 1 exactly when the result is 1, which is the cleanest way to confirm that two numbers are coprime.
  • Handles large integers safely: The LCM is computed as floor(a / gcf) * b, and the displayed value is clamped to Number.MAX_SAFE_INTEGER (about 9.007 x 10^15) whenever the exact product would lose precision in a JavaScript double.

If the GCF is a step on the way to something else, the same value feeds other tools. A prime number checker tests each input independently for primality, and a full fraction calculator reduces, adds, subtracts, multiplies, and divides fractions using the GCF as part of its internal simplification step.

The prime number checker on the site is a useful sanity check: enter either of the two inputs and it returns true if that input is prime, so the coprime flag of 1 in this panel can be confirmed one input at a time. The GCF, the coprime flag, and the prime factorization rows together tell the same story from three angles.

Factors That Affect Your Results

Three variables drive the value the result panel reports, and two limitations tell you when to verify the answer by hand.

Shared Prime Factors

The result is the product of every prime that appears in both factorizations, raised to the smaller exponent.

Input Magnitude

Larger inputs do not change the GCF, but they do grow the LCM. When the exact LCM would exceed Number.MAX_SAFE_INTEGER, the displayed value is clamped to the safe-integer ceiling so the panel never shows a rounded number.

Negative or Zero Inputs

Zero is rejected because gcf(0, 0) is undefined. Negative values are read as their absolute value, so the result matches the positive counterpart.

  • The LCM is computed as floor(a / gcf) * b, and any value above Number.MAX_SAFE_INTEGER (about 9.007 x 10^15) is clamped to the safe-integer ceiling rather than rendered as a rounded double.
  • The prime factorization rows use trial division up to the integer square root, so factorization is fast for inputs up to about 10^12 and slow near the 10^15 ceiling.

When the inputs are out of range, switching to a tool that uses big-integer arithmetic is the safer choice. Britannica traces the algorithm back to Euclid's Elements around 300 BCE.

For larger prime-product work, a factorial identity is often the next step once the GCF of the smaller building blocks is known.

According to Britannica, the Euclidean algorithm is an ancient method for finding the greatest common divisor of two integers, attributed to the Greek mathematician Euclid and described in his Elements around 300 BCE.

The site factorial calculator takes that next step: it returns the product of consecutive integers from 1 to n, and the GCF of consecutive integers is closely tied to the factorial identities used in combinatorics and probability.

GCF calculator interface showing two integer inputs, the greatest common factor result, prime factorization of each input, LCM, Euclidean step count, and a coprime flag
GCF calculator interface showing two integer inputs, the greatest common factor result, prime factorization of each input, LCM, Euclidean step count, and a coprime flag

Frequently Asked Questions

Q: What is a GCF calculator?

A: It finds the greatest common factor of two whole numbers, the largest positive integer that divides both inputs without a remainder. The result panel also shows each prime factorization, the LCM, the Euclidean step count, and a coprime flag.

Q: How do you find the GCF of two numbers?

A: Either list the factors of both numbers and pick the largest one in common, or use the Euclidean algorithm: replace the larger number with the remainder of dividing it by the smaller and repeat until the remainder is 0.

Q: What is the difference between GCF and GCD?

A: There is no mathematical difference. GCF (greatest common factor), GCD (greatest common divisor), and HCF (highest common factor) all refer to the largest positive integer that divides two numbers exactly.

Q: What is the GCF of two coprime numbers?

A: The GCF of any two coprime numbers is 1, because 1 is the only positive integer that divides both of them. The coprime flag in the panel turns to 1 in that case.

Q: How do you use the GCF to simplify a fraction?

A: Divide the numerator and the denominator by their GCF. For 48/18, the GCF is 6, so dividing both terms by 6 gives 8/3, the simplest form.

Q: What is the relationship between GCF and LCM?

A: GCF and LCM are linked by the identity a * b = GCF * LCM, so once the GCF is known the LCM is a * b divided by the GCF. The calculator applies this identity automatically.