GCD Calculator
Calculate the Greatest Common Divisor (GCD) of two or more numbers using the Euclidean algorithm. Instant result.
What is GCD?
We call the Greatest Common Divisor (GCD) the largest number that divides two or more integers exactly. To find it, use the Euclidean algorithm: divide the larger by the smaller, then redo the operation with the divisor and the remainder until that remainder reaches zero.
Here is an example. GCD(12, 8) → 12 = 1×8 + 4 → 8 = 2×4 + 0 → GCD = 4.
Greatest common divisor and the Euclidean algorithm
The greatest common divisor gcd(a, b) is the largest positive integer that divides both a and b with zero remainder. The Euclidean algorithm computes it efficiently using the identity gcd(a, b) = gcd(b, a mod b), repeated until b = 0 — at which point the answer is a. Example: gcd(48, 18) → gcd(18, 12) → gcd(12, 6) → gcd(6, 0) = 6. The procedure dates back to Euclid's Elements (Book VII, c. 300 BC) and runs in O(log min(a, b)) — dramatically faster than trial-factoring both numbers, which is O(sqrt n).
A useful identity links GCD and LCM: a · b = gcd(a, b) · lcm(a, b). Two integers are coprime when their GCD equals 1.
Where the GCD shows up
- Reducing fractions to lowest terms:
18/48 = 3/8after dividing both by gcd = 6. - RSA cryptography uses the extended Euclidean algorithm to compute modular inverses of the public exponent.
- Partitioning quantities into equal groups (e.g., the largest tile size that paves a rectangular floor without cuts).
- Diophantine equations
ax + by = chave integer solutions iffgcd(a, b) | c.
FAQ
Why prefer Euclid over factoring both numbers? Euclid runs in O(log min(a, b)); trial-division factoring is O(sqrt n). For 20-digit numbers Euclid finishes in microseconds while factoring may take seconds or minutes.
What is gcd(0, n)? By convention gcd(0, n) = n for any positive n, since every integer divides 0.
How does GCD scale to more than two numbers? Apply pairwise: gcd(a, b, c) = gcd(gcd(a, b), c). The operation is associative.
Can the GCD be negative? No — by definition the GCD is the largest positive divisor. Negative signs in inputs are dropped.
Related Tools
Rent Adjustment Calculator
Compute annual rent adjustment by IGP-M or IPCA accumulated in the last 12 months (manually configurable).
Pregnancy Calculator
Compute estimated due date (EDD), gestational age and trimester from the last menstrual period (LMP).
Fertile Period Calculator
Compute fertile window and ovulation day from the first day of the last cycle and the average cycle length.
Calculate the GCD (greatest common divisor)
The greatest common divisor is the largest number that divides two or more values at the same time. It shows up as the basis for simplifying fractions and in plenty of maths problems. This calculator reaches the GCD through Euclid's algorithm, which is efficient and exact.
Enter two or more numbers and the GCD comes out next. It works for reducing fractions to lowest terms, splitting quantities into equal groups, solving school exercises or any situation where you need the largest common factor between the values.
Instead of doing the decomposition on paper, the calculation runs straight in the browser. A quick reference for one of arithmetic's most basic operations.