Skip to content
ZeroServer.tools

Modular Arithmetic Calculator

Calculate mod, modular inverse, and modular exponentiation.

Result

17

Step-by-step

17 mod 26 = 17

⌊17 ÷ 26⌋ = 0  →  remainder = 17

Clock Diagram — mod 26

012345678910111213141516171819202122232425
a ≡ 17 (mod 26)
result = 17

About Modular Arithmetic Calculator

Modular arithmetic treats numbers like positions on a clock — values wrap around once they exceed the modulus. This calculator handles mod, modular addition, subtraction, multiplication, fast exponentiation (square-and-multiply with BigInt for arbitrary precision), modular inverse via the extended Euclidean algorithm, GCD, and congruence checks. Essential for cryptography (RSA, Diffie-Hellman, elliptic curves), computer science (hash tables, checksums, cyclic buffers), and number theory.

Built and maintained by Meet Shah · Last updated

What this tool is used for

  • Computing a modular inverse for a cryptography exercise.
  • Working out a modular exponentiation without overflowing.
  • Checking a congruence for a number theory problem.
  • Verifying a checksum that is defined modulo a value.
  • Confirming an implementation against a known result.

Frequently Asked Questions

Why does a negative number give a positive remainder?
Because mathematical modulo always returns a value in 0…n−1, while most programming languages' `%` keeps the sign of the dividend — so −7 % 3 is −1 in C, Java and JavaScript but 2 in mathematics and in Python. This follows the mathematical convention.
What is a modular inverse?
The number that multiplies with yours to give 1 under the modulus: 3 × 5 = 15 ≡ 1 (mod 7), so 5 is the inverse of 3 mod 7. It exists only when the two numbers are coprime, and it is what makes division possible in modular arithmetic.
How is modular exponentiation done without huge numbers?
By square-and-multiply, reducing at every step, so the intermediate values never exceed the modulus. That is what makes RSA feasible: computing 2^65537 mod n directly is impossible, and computing it this way takes microseconds.
Where does this show up outside cryptography?
Clock and calendar arithmetic, hash-table bucketing, the check digits on ISBNs and IBANs (mod 11 and mod 97), cyclic buffers, and Zeller's congruence for the day of the week. Anywhere counting wraps around, the arithmetic is modular.
Is the arithmetic exact for large values?
Yes — it runs on BigInt, so a 300-digit modulus behaves correctly. Doing this with ordinary JavaScript numbers loses precision above 2⁵³ and silently returns wrong remainders, which is exactly the kind of bug that never surfaces in small tests.

Common errors and gotchas

  • Expecting a modular inverse to exist when the numbers are not coprime, which is when it does not.
  • Assuming the remainder of a negative number is negative, which differs between mathematical convention and most languages.
  • Computing a power before the modulus, which overflows long before the answer is reached.
  • Confusing the modulus with the divisor's remainder in a language that implements truncated division.
  • Treating modular arithmetic as ordinary arithmetic, where division does not work the same way.

Related Calculators tools

Private & free — this tool runs entirely in your browser.