Number theory calculator

GCD of Two Numbers Calculator

Find common divisors quickly with transparent steps and several methods. Explore factors, LCM, coefficients, ratios, and checks. Save exports and calculation history securely.

Enter Two Integers

Positive, negative, zero, and very large whole numbers are supported by the main Euclidean and extended calculations.

Example: 48, -24, or a large integer.
At least one input must be nonzero.
The reliable Euclidean result is always calculated.
Display options

Recent Calculation History

Stored only in this browser.

Example Data Table

First numberSecond numberGCDLCMRelationship
48186144Shared factors
100252510025 divides 100
17131221Coprime
015150Zero case
-24361272Signs ignored for GCD
27019268,640Multiple Euclidean steps

Formula Used

Euclidean recurrence

gcd(a, b) = gcd(b, a mod b)
Continue until the remainder becomes zero. The last nonzero divisor is the GCD.

GCD and LCM identity

gcd(a, b) × lcm(a, b) = |a × b|

Bézout identity

ax + by = gcd(a, b)
The extended Euclidean algorithm finds one integer pair x and y.

Zero rules

gcd(a, 0) = |a| for nonzero a. The value gcd(0, 0) is undefined.

How to Use This Calculator

  1. Enter the first whole number. A leading plus or minus sign is allowed.
  2. Enter the second whole number. Do not enter commas, spaces, decimals, or exponent notation.
  3. Select one detailed method or choose all supported methods.
  4. Choose whether to list divisors, verify the GCD-LCM identity, or show the extended table.
  5. Press Calculate GCD. The main result appears above the form.
  6. Review the Euclidean steps, prime factors, coefficients, ratio, fraction, and relationship checks.
  7. Copy the result, export CSV, create a PDF, print the page, or copy a shareable link.

Understanding the Greatest Common Divisor

The greatest common divisor is the largest positive integer that divides two integers without a remainder. It is also called the greatest common factor or highest common factor. These names describe the same number. The calculator uses absolute values for the main GCD, so negative signs do not make the result negative.

Why the Euclidean algorithm matters

Listing every factor can work for small values. It becomes slow for large values. The Euclidean algorithm is usually much faster. It replaces a pair of numbers with the smaller number and the remainder. Each replacement keeps the same GCD. The process ends when a remainder becomes zero.

For 48 and 18, divide 48 by 18. The remainder is 12. Next, divide 18 by 12. The remainder is 6. Finally, divide 12 by 6. The remainder is zero. Therefore, the last nonzero divisor is 6.

Prime factors and common factors

Prime factorization gives another clear method. Write each number as a product of primes. Keep only the primes shared by both numbers. Use the smaller exponent for every shared prime. Multiplying those shared prime powers gives the GCD.

Every positive common divisor must divide the GCD. This fact makes the common factor list easy to understand. Once the GCD is known, its positive divisors are exactly the positive numbers that divide both inputs.

Reduced ratios and fractions

A ratio can be reduced by dividing both terms by their GCD. The same rule reduces a fraction. For example, 48:18 becomes 8:3 after division by 6. The fraction 48/18 also becomes 8/3. A GCD of one means the ratio or fraction is already in lowest terms.

LCM and verification

The least common multiple is the smallest nonnegative number divisible by both inputs. For nonzero integers, the product of the GCD and LCM equals the absolute product of the inputs. This calculator displays both sides of that identity, which provides a useful arithmetic check.

Bézout coefficients

The extended Euclidean algorithm does more than find a divisor. It also finds integers x and y that satisfy ax + by = gcd(a, b). These coefficients support modular inverses, congruences, cryptography, and linear Diophantine equations. When the GCD is one, a modular inverse may exist.

Special values

Zero needs careful treatment. The GCD of zero and a nonzero integer is the absolute value of the nonzero integer. The LCM in that case is zero. The GCD of zero and zero is not defined because no greatest positive common divisor exists. The calculator reports this case clearly.

Choosing a method

Use the Euclidean algorithm for fast general work. Use prime factorization when learning factor structure. Use common factors for small classroom examples. Use the binary method when studying low-level integer algorithms. Use repeated subtraction for intuition, not speed. Use the extended method when coefficients or modular arithmetic are required.

Frequently Asked Questions

What is the GCD of two numbers?

It is the largest positive integer that divides both numbers exactly. GCD, GCF, and HCF usually mean the same thing.

Can the calculator use negative numbers?

Yes. It uses absolute values when finding the GCD, so the main result is always nonnegative.

What happens when one input is zero?

The GCD equals the absolute value of the nonzero input. The LCM is zero.

Why is GCD(0, 0) undefined?

Every positive integer divides both zeros. Therefore, no greatest positive common divisor exists.

What does coprime mean?

Two integers are coprime when their GCD is one. They do not share any prime factor.

How is the LCM calculated?

For nonzero inputs, LCM equals the absolute product divided by the GCD. The implementation divides before multiplying to reduce intermediate size.

What are Bézout coefficients?

They are integers x and y satisfying ax + by = gcd(a, b). The extended Euclidean algorithm finds them.

When does a modular inverse exist?

The first number has an inverse modulo the second when their GCD is one and the modulus is greater than one.

Why can prime factorization be unavailable?

Factoring large integers may require heavy computation. The page limits factorization while keeping the Euclidean result exact.

Why is repeated subtraction limited?

Repeated subtraction can require many iterations. The Euclidean algorithm reaches the same answer more efficiently.

Can I enter very large integers?

Yes. Core decimal arithmetic, Euclidean steps, LCM, ratios, and Bézout coefficients use string-based arbitrary-length operations.

Does the calculator accept decimals?

No. GCD is defined here for integers, so decimal and scientific notation inputs are rejected.

Where is calculation history stored?

Recent entries are stored in local browser storage. They are not sent to a separate history service.

Can I share a calculation?

Yes. The share button creates a link containing the inputs and selected display settings.

Related Calculators

Average Calculator StatisticsGeometric Mean CalculatorInter Quartile Range CalculatorLower Quartile CalculatorMaximum CalculatorMean Calculator StatisticsMedian Calculator StatisticsMidhinge Calculator StatisticsMid Range Calculator StatisticsMode Calculator Statistics

Important Note: All the Calculators listed in this site are for educational purpose only and we do not guarentee the accuracy of results. Please do consult with other sources as well.