Gcd Calculator - GCD and LCM via Euclidean Steps

Use the GCD calculator to find the greatest common divisor of two integers, the LCM, the Euclidean step count, and a coprime flag.

Updated: June 16, 2026 • Free Tool

Gcd Calculator

Enter an integer; negative values are converted to their absolute value. Decimal inputs are floored before the algorithm runs.

Enter an integer; negative values are converted to their absolute value. The Euclidean algorithm is symmetric, so the order does not change the result.

Results

GCD (a, b)
0
LCM (a, b) 0
Euclidean steps 0
Coprime (1 = yes) 0

What Is the GCD Calculator?

A GCD calculator is a browser-based tool that finds the greatest common divisor of two integers using the Euclidean algorithm and shows the result alongside the least common multiple, the step count, and a coprime flag in the same result panel.

  • Simplifying fractions: Divide numerator and denominator by the GCD to reduce a fraction to its lowest terms.
  • Homework checks: Verify a hand-worked GCD problem for two integers, especially when the pair is large.
  • Modular arithmetic and cryptography: Confirm that two numbers are coprime (GCD = 1) before choosing a modulus for an inverse or a public-key setup.
  • Music, scheduling, and packing: Use the GCD to space repeating events evenly, or use the LCM to find when two cycles line up.

The input panel holds the two integer inputs (a and b) and the result panel reports the GCD, the LCM, the Euclidean step count, and a coprime flag. The coprime flag is set to 1 when the GCD equals 1, the standard test for treating a pair as 'sharing no common factor'. Try 48 in a and 18 in b: the result panel shows GCD 6, LCM 144, three Euclidean steps, and coprime 0.

When the GCD is the divisor you need to reduce a fraction to lowest terms, Simplify Fractions Calculator applies that same step to the numerator and denominator in one go.

How the GCD Calculator Works

The calculator reads the two integer inputs, runs the Euclidean algorithm in your browser, and refreshes the result panel on every keystroke so the GCD, LCM, step count, and coprime flag stay in sync with the numbers you typed.

gcd(a, 0) = a; gcd(a, b) = gcd(b, a mod b)
  • a: First integer. Negative values are converted to their absolute value, and decimals are floored.
  • b: Second integer. Negative values are converted to their absolute value, and decimals are floored. The algorithm is symmetric, so order does not change the result.
  • gcd: Greatest common divisor, the largest positive integer that divides both a and b.
  • lcm: Least common multiple, computed as floor(a / gcd) * b so the intermediate product does not overflow the JavaScript safe-integer range.

Every recalculation runs in your browser on each input or change event, so the four result rows update without a page reload. The step counter tells you how many iterations the Euclidean loop ran; coprime pairs and adjacent Fibonacci numbers take more steps. The form coerces decimals with floor and negatives with absolute value before the algorithm runs, and the LCM uses floor(a / gcd) * b to do the division before the multiplication; that ordering keeps the intermediate product within the JavaScript safe-integer range, although the final LCM value can still exceed Number.MAX_SAFE_INTEGER for very large input pairs.

GCD of 12 and 18

a = 12, b = 18

gcd(12, 18) = gcd(18, 12 mod 18) = gcd(18, 12) = gcd(12, 6) = gcd(6, 0) = 6

GCD: 6, LCM: 36, Steps: 3, Coprime: 0

The algorithm replaces the larger number with the remainder three times, then stops. LCM follows from a * b / gcd = 12 * 18 / 6 = 36.

According to Wikipedia, The greatest common divisor (gcd) of two non-zero integers is the largest positive integer that divides each of them, and the Euclidean algorithm computes it by repeatedly replacing the larger number with the remainder of the division.

According to Khan Academy, The Euclidean algorithm finds the GCD by replacing the larger with the remainder of dividing the larger by the smaller, repeating until the remainder is zero, at which point the other number is the GCD.

Because the Euclidean algorithm replaces the larger input with a mod b on every iteration, Modulo Calculator is the natural companion for checking the remainders along the way.

Key Concepts Behind the GCD

Four small ideas cover every GCD calculation, from a basic two-integer pair to a coprime flag you can hand to a fraction simplifier.

Greatest common divisor

The GCD of two integers a and b is the largest positive integer that divides both without a remainder. It is also called the greatest common factor (GCF) or the highest common factor (HCF); all three names describe the same number.

Euclidean algorithm

The Euclidean algorithm computes the GCD by repeatedly replacing the larger number with the remainder of dividing it by the smaller. When the remainder is zero, the other number is the GCD. The algorithm runs in logarithmic time, so even very large inputs converge in a handful of steps.

Least common multiple

The LCM is the smallest positive integer that is a multiple of both a and b. It is tied to the GCD by the identity a * b = gcd(a, b) * lcm(a, b), so once the GCD is known the LCM is a * b / gcd.

Coprime pairs

Two integers are coprime (or relatively prime) when their GCD is exactly 1, meaning they share no common factor other than 1. Coprime pairs are the standard precondition for modular inverses, RSA key generation, and fraction reduction.

When the coprime flag stays at 1 and you want to know which input is prime, Prime Number Checker confirms the primality of each operand in a single step.

How to Use the GCD Calculator

Type two integers, read the GCD and the companion outputs in the result panel, and use the coprime flag as a quick check for fraction work.

  1. 1 Enter the first integer: Type the first integer in the input labeled a. Negative values are converted to their absolute value, and decimal values are floored, so -12 becomes 12 and 12.7 becomes 12.
  2. 2 Enter the second integer: Type the second integer in the input labeled b. The result panel updates on every keystroke, and the same absolute-value and floor rules apply.
  3. 3 Read the GCD and LCM: Look at the primary result tile for the GCD, then the LCM row underneath. The LCM equals a * b / gcd, the smallest positive integer that is a multiple of both inputs.
  4. 4 Use the coprime flag: A coprime flag of 1 means the pair is safe for modular inverses and fraction reduction. A flag of 0 means the pair shares a factor and needs the GCD to reduce.
  5. 5 Reset to start over: Press Reset to restore the default integer pair (48 and 18).

Try 48 in a and 18 in b. The result tile reads 6, the LCM row reads 144, the step count reads 3, and the coprime flag reads 0. Switching the second input to 19 flips the GCD to 1, the LCM to 912, and the coprime flag to 1.

When the inputs come from a combinatorics problem and you also need n! for the same n, Factorial Calculator returns the factorial in a separate result panel.

Benefits of Using This GCD Calculator

The tool gives you the GCD, the LCM, the step count, and a coprime flag in a single result panel, so you never have to switch calculators just to confirm the LCM or check whether a pair is coprime.

  • GCD and LCM in one panel: The result panel shows the GCD and the LCM together, so a fraction simplification and a cycle-alignment check use the same calculator.
  • Euclidean step count: The step counter tells you how many iterations the algorithm ran. Coprime numbers and adjacent Fibonacci numbers take more steps, which is a useful sanity check.
  • Coprime flag for modular work: The coprime flag returns 1 when the GCD is 1, the standard signal that a pair is safe for modular inverses, RSA key generation, and fraction reduction.
  • Real-time recalculation: Every keystroke updates the four result rows, so you can iterate over a list of integer pairs without pressing a button between each one.

The coprime flag is the biggest practical payoff: a 1 means the pair is safe for modular inverses and fraction reduction, while a 0 means the GCD row tells you the factor to divide out.

Pairs of adjacent Fibonacci numbers are famous for taking many Euclidean steps, so Fibonacci Calculator is a quick way to generate the inputs that stress the algorithm.

Factors That Affect Your GCD Result

Two integer inputs shape the answer, and a small set of caveats keeps the result honest for zero, large, and coprime pairs.

Magnitude of the inputs

Larger integer pairs tend to take more Euclidean steps before the remainder reaches zero. The step count row reports this directly, so you can see the convergence without running the loop by hand.

Shared factors between a and b

When a and b share a common factor, the GCD is at least that factor. Coprime pairs (GCD = 1) have no shared factors other than 1, and the coprime flag reports that condition as 1.

Zero in either input

When one input is zero, the GCD is the non-zero input and the LCM is zero. When both inputs are zero, the GCD and LCM are both zero by convention.

  • The calculator accepts integers in the JavaScript number range. Decimal entries are floored and negative entries are turned positive with absolute value, but signed rational or very large big-integer inputs are out of scope.
  • The LCM is computed as floor(a / gcd) * b rather than a * b / gcd, so the intermediate product stays within the JavaScript safe-integer range. The final LCM value can still exceed Number.MAX_SAFE_INTEGER (2 to the 53) for very large input pairs, and a dedicated big-integer library is needed for that scale.

According to Wikipedia, GCD(0, 0) is 0 by convention and GCD(0, n) is |n| for n != 0, with the identity a * b = gcd(a, b) * lcm(a, b) tying the LCM to the GCD.

GCD calculator showing two integer inputs, the greatest common divisor, the least common multiple, the Euclidean step count, and a coprime flag.
GCD calculator showing two integer inputs, the greatest common divisor, the least common multiple, the Euclidean step count, and a coprime flag.

Frequently Asked Questions

Q: What is the GCD calculator used for?

A: The GCD calculator finds the greatest common divisor of two integers using the Euclidean algorithm, then reports the LCM, the step count, and a coprime flag in the same result panel. It is a fast way to simplify fractions, check whether a pair of numbers is coprime, or compute the LCM without re-typing the inputs.

Q: How do you find the GCD of two numbers using the Euclidean algorithm?

A: Start with two integers a and b, divide the larger by the smaller, and replace the larger with the remainder. Repeat until the remainder is zero; the other number at that point is the GCD. The step count row in the result panel reports how many iterations this took for your pair.

Q: What is the GCD of 0 and a number?

A: GCD(0, n) is n, the non-zero input, because every positive integer divides zero. GCD(0, 0) is 0 by convention, although some textbooks treat it as undefined; the calculator uses 0 for the (0, 0) case to keep the result finite and machine-readable.

Q: How do you find the GCD of negative numbers?

A: The GCD is defined for the absolute values of the inputs, so gcd(-12, 8) equals gcd(12, 8) = 4. The calculator takes the absolute value of each entry before running the Euclidean loop, so a negative input is treated like its positive counterpart in the result panel.

Q: What is the relationship between GCD and LCM?

A: GCD and LCM are tied by the identity a * b = gcd(a, b) * lcm(a, b), so once the GCD is known the LCM is a * b / gcd. The calculator reports both in the same result panel, with the LCM built from floor(a / gcd) * b to do the division first; the intermediate product stays within the JavaScript safe-integer range, but the final LCM value can still exceed Number.MAX_SAFE_INTEGER for very large input pairs.

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

A: Divide the numerator and the denominator by their GCD to reduce the fraction to lowest terms. For example, 48 / 18 has a GCD of 6, so dividing both by 6 gives 8 / 3, the simplest form. The coprime flag in the result panel turns to 1 when the fraction is already in lowest terms.