Greatest Common Divisor Calculator — GCD / HCF

GCD

Steps

How the Greatest Common Divisor (GCD) Works

The greatest common divisor (GCD) is the largest positive integer that divides two or more numbers without leaving a remainder. Also known as the greatest common factor (GCF) or highest common factor (HCF), it is one of the most fundamental concepts in number theory. According to Wolfram MathWorld, the GCD appears in Euclid's Elements (circa 300 BC) as Proposition 2 of Book VII, making the Euclidean algorithm one of the oldest known algorithms still in active use today.

The GCD has widespread practical applications: simplifying fractions, solving Diophantine equations, computing modular inverses in cryptography, and determining rhythmic patterns in music theory. In engineering, it helps find the largest tile size that fits evenly into a rectangular floor. This calculator uses the Euclidean algorithm to find the GCD of two or three numbers and shows the step-by-step computation. For related operations, try our LCM Calculator or Fraction Calculator.

The Euclidean Algorithm Formula

The Euclidean algorithm is based on a simple recursive property:

GCD(a, b) = GCD(b, a mod b), repeated until b = 0, at which point GCD = a.

Each variable: a is the larger number, b is the smaller number, and a mod b is the remainder when a is divided by b. The algorithm terminates because the remainder decreases with each step. For three numbers: GCD(a, b, c) = GCD(GCD(a, b), c).

Worked example: Find GCD(48, 36). Step 1: 48 = 1 x 36 + 12. Step 2: 36 = 3 x 12 + 0. The last non-zero remainder is 12, so GCD(48, 36) = 12. This means 12 is the largest number that divides both 48 and 36 evenly.

Key Terms You Should Know

GCD Methods Compared

Method Time Complexity Best For Notes
Euclidean AlgorithmO(log(min(a,b)))All casesFast, works for very large numbers
Prime FactorizationO(sqrt(n))Small numbers, educationEasy to understand visually
Binary GCD (Stein's)O(log(a) x log(b))Computer implementationsUses bit shifts instead of division
Listing FactorsO(n)Very small numbersImpractical for numbers > 1000

Practical GCD Examples

Example 1 -- Simplifying Fractions: To simplify 84/126, find GCD(84, 126). Using the Euclidean algorithm: 126 = 1 x 84 + 42, then 84 = 2 x 42 + 0. GCD = 42. So 84/126 = (84/42)/(126/42) = 2/3. Use our Fraction Calculator for more fraction operations.

Example 2 -- Tiling a Floor: A room is 120 inches by 84 inches. The largest square tile that fits evenly is GCD(120, 84) = 12 inches. You would need (120/12) x (84/12) = 10 x 7 = 70 tiles with no cutting required.

Example 3 -- Three Numbers: Find GCD(24, 36, 60). First, GCD(24, 36): 36 = 1 x 24 + 12, 24 = 2 x 12 + 0, so GCD = 12. Then GCD(12, 60): 60 = 5 x 12 + 0, so GCD(24, 36, 60) = 12. Check with our Prime Factorization Calculator: 24 = 2^3 x 3, 36 = 2^2 x 3^2, 60 = 2^2 x 3 x 5. Common factors: 2^2 x 3 = 12.

Tips for Working with GCD

GCD in Modern Computing and Cryptography

The Euclidean algorithm remains one of the most important algorithms in computer science. According to Donald Knuth's The Art of Computer Programming, it may be the oldest non-trivial algorithm that has survived to the present day. The Extended Euclidean Algorithm (which also finds coefficients x and y satisfying ax + by = GCD(a, b)) is critical to RSA key generation, which secures an estimated 90% of internet encryption. The algorithm runs in O(log(min(a,b))) time, meaning it can compute the GCD of numbers with thousands of digits in milliseconds -- a property that makes modern public-key cryptography practical.

Frequently Asked Questions

What is the Euclidean algorithm and how does it work?

The Euclidean algorithm finds the GCD by repeatedly dividing the larger number by the smaller and taking the remainder until the remainder reaches zero. The last non-zero remainder is the GCD. For example, GCD(48, 18): 48 = 2 x 18 + 12, then 18 = 1 x 12 + 6, then 12 = 2 x 6 + 0, so GCD = 6. Documented in Euclid's Elements around 300 BC, it is one of the oldest algorithms still used today, running in O(log n) time complexity, which makes it efficient even for numbers with hundreds of digits.

What is GCD used for in real life?

GCD has numerous practical applications. In math class, it simplifies fractions to lowest terms (e.g., 84/126 becomes 2/3 when divided by GCD of 42). In construction, it determines the largest tile that fits a room without cutting. In scheduling, it helps find when periodic events coincide. In computer science, the Extended Euclidean Algorithm is essential to RSA encryption, which secures online banking and communications. Music theory uses GCD to analyze rhythmic patterns and time signatures.

Is GCD the same as HCF and GCF?

Yes, GCD (Greatest Common Divisor), HCF (Highest Common Factor), and GCF (Greatest Common Factor) all refer to the same mathematical concept -- the largest number that divides two or more numbers evenly. GCD and GCF are the standard terms in American mathematics education, while HCF is more commonly used in British, Australian, and Indian curricula. Some textbooks also use the term "greatest common measure" (GCM), though this is less common.

How do I find the GCD of three or more numbers?

To find the GCD of three or more numbers, compute the GCD of the first two numbers, then find the GCD of that result with the third number, and so on. For example, GCD(24, 36, 60): first compute GCD(24, 36) = 12, then GCD(12, 60) = 12. The order does not matter because GCD is both commutative and associative. This calculator supports up to three numbers, but the same chaining method works for any quantity of inputs.

What does it mean when two numbers have a GCD of 1?

When GCD(a, b) = 1, the numbers are called coprime or relatively prime. This means they share no common factor other than 1. For example, 8 and 15 are coprime even though neither is a prime number (8 = 2^3, 15 = 3 x 5 -- they share no prime factors). Coprimality is crucial in cryptography: RSA encryption requires that the public exponent e be coprime with the totient of n. It also means the fraction a/b is already in its simplest form.

Related Calculators