SCIENCE & MATHS

Modulo Calculator

a mod n on integers of any size — the floored remainder and the truncated one languages return for negatives — with quotient, congruence, inverse and a^e mod n.

Floored and truncated remainders with their quotients, the identity a = q·n + r, whether a ≡ b (mod n), the GCD, the modular inverse when it exists and a^e mod n.

Example: −7 mod 3 is 2 (−7 = −3 × 3 + 2) while JavaScript’s −7 % 3 is −1; 17 mod 5 = 2, the inverse of 17 mod 5 is 3, and 17¹⁰⁰ mod 5 = 1 by square-and-multiply.

v0.1.0 · last reviewed 21 September 2026
Loading the workspace…
BUILT TO BE UNDERSTOOD

Two remainders,
one is the maths.

Why languages disagree on negative operands, what the inverse and modular power are, and how they are computed.

Floored and truncated

Mathematically a mod n is the remainder in [0, n): −7 mod 3 = 2 because −7 = −3 × 3 + 2. C, Java, JavaScript and Go truncate the quotient toward zero instead and return −1 for −7 % 3; Python's %, spreadsheets' MOD and most calculators return 2. The page shows both with their quotients so a result can be matched to the tool that produced it.

Inverse and power

a⁻¹ mod n exists only when gcd(a, n) = 1 and comes from the extended Euclidean algorithm (Bézout coefficients); a^e mod n is computed by square-and-multiply, so 17¹⁰⁰ mod 5 needs seven squarings, not a hundred-digit intermediate. Congruence a ≡ b (mod n) means both leave the same floored remainder.

Limits

All arithmetic is on exact integers of any size; a negative modulus is handled with |n| for the floored result and as JavaScript computes it for the truncated one. Nothing leaves the browser; the same four anonymous usage counts as the rest of the site apply.

SOURCES

  • Floored remainder r = a − n·⌊a/n⌋ in [0, |n|); truncated remainder keeps the sign of a; inverse by the extended Euclidean algorithm; modular exponentiation by square-and-multiply

Last reviewed 21 September 2026. How results are checked: How we verify.