Find the canonical remainder of a modulo n.
What this modular arithmetic calculator does
This calculator helps you perform arithmetic inside a modular system, where values “wrap around” after reaching a modulus. If you have ever used a 12-hour clock, you already understand modular arithmetic in practice. Here, you can quickly compute:
- Simple reduction:
a mod n - Modular addition, subtraction, and multiplication
- Fast modular exponentiation for large powers
- Modular inverse when it exists
- Modular division using inverses
How modular arithmetic works
Congruence and remainder classes
Two integers are congruent modulo n if they leave the same remainder after division by n. We write:
a ≡ b (mod n).
For example, 17 ≡ 5 (mod 12), because both numbers leave remainder 5 when divided by 12.
Canonical result range
In this calculator, results are normalized into the standard range 0 to n - 1.
That means negative results are converted to an equivalent nonnegative remainder. For example:
-3 mod 7 = 4.
How to use this calculator
- Choose an operation from the dropdown.
- Enter modulus
n(must be an integer greater than 1). - Enter
a, andbif the operation needs it. - Click Calculate to see the expression and result.
Tip: You can enter very large integers. The calculator uses integer-safe arithmetic with JavaScript BigInt,
so results remain exact for huge values.
Operation guide and examples
1) Normalize: a mod n
Use this when you only need the remainder class of a number. Example:
29 mod 6 = 5.
2) Addition/Subtraction/Multiplication
These behave exactly like ordinary arithmetic, then reduce modulo n.
Example with n = 11:
(8 + 9) mod 11 = 6(3 - 10) mod 11 = 4(7 × 8) mod 11 = 1
3) Exponentiation: a^b mod n
This operation is crucial in cryptography and number theory. The calculator uses fast exponentiation,
so even large powers compute quickly.
Example: 5^117 mod 19.
4) Multiplicative inverse: a^-1 mod n
An inverse exists only when gcd(a, n) = 1. If it exists, then:
a × a^-1 ≡ 1 (mod n).
Example: 3^-1 mod 11 = 4, because 3 × 4 = 12 ≡ 1 (mod 11).
5) Division modulo n
Division is defined by multiplying by the inverse:
a / b mod n = a × b^-1 mod n.
This only works if b has an inverse modulo n.
Why modular arithmetic matters in real life
- Cryptography: RSA, Diffie-Hellman, and elliptic-curve systems depend on modular arithmetic.
- Computer science: Hashing, pseudo-random generation, and circular buffers use modular operations.
- Scheduling: Repeating events (weekly, monthly cycles) are modular by nature.
- Error detection: Checksums and coding techniques often include modulo computations.
Common mistakes to avoid
- Using modulus
n = 1(not meaningful for most modular tasks). - Trying modular inverse when
gcd(a, n) ≠ 1. - Treating modular division as ordinary division without checking invertibility.
- Forgetting to normalize negative values into the standard remainder range.
Quick FAQ
Can I use negative numbers?
Yes. Inputs may be negative, and the final result is always shown as a nonnegative remainder.
Can this calculator handle large integers?
Yes. It uses exact integer arithmetic, so large whole numbers are supported.
Why did I get an inverse error?
A modular inverse exists only when the number and modulus are coprime. If they share a factor greater than 1, inverse-based operations are undefined.