Modulo Calculator
Compute modular arithmetic on integers: simple modulo (a mod n), modular addition, subtraction, multiplication, fast modular exponentiation (a^b mod n), and congruence checks (a ≡ b mod n), with a step-by-step breakdown. Uses the true mathematical modulo (always non-negative for a positive modulus).
Input
Output
Guides
The Modulo Calculator performs modular arithmetic on integers of any size and shows the working, step by step. Enter your values, pick an operation, and it computes the result instantly in your browser — nothing is sent to a server.
What is modular arithmetic?
Modular arithmetic is "clock arithmetic": numbers wrap around after reaching a fixed value called the modulus. On a 12-hour clock, 3 hours after 11 o'clock is 2 o'clock, because 11 + 3 = 14 and 14 mod 12 = 2. The result of a mod n is the remainder left when a is divided by n, and it always lands in the range 0 to n − 1 for a positive modulus.
Modular arithmetic underpins a huge amount of everyday computing: hashing, checksums, cryptography (RSA, Diffie–Hellman), random-number generators, cyclic buffers, and calendar calculations all rely on it.
True modulo vs. the remainder operator
There is a subtle but important difference between the mathematical modulo and the % operator most programming languages provide. JavaScript's % is a truncated remainder that keeps the sign of the dividend, so -7 % 3 is -1. The mathematical modulo, however, is always non-negative when the modulus is positive, so -7 mod 3 is 2 (because -7 = 3 × (-3) + 2).
This tool reports the true mathematical (Euclidean) modulo as the primary Result, and also shows the truncated % value alongside it so you can see exactly where and why they differ. All arithmetic uses arbitrary-precision integers, so results stay exact even for very large numbers.
Operations
- Simple Modulo —
a mod n, the remainder ofa ÷ n. - Modular Addition / Subtraction / Multiplication — computes
(a + b) mod n,(a − b) mod n, or(a × b) mod n. The breakdown demonstrates the distributive property: you can reduce each operand modnfirst and get the same answer. - Modular Exponentiation —
a^b mod n, computed with the fast square-and-multiply algorithm. Rather than raisingato a huge power and then reducing, it reduces modulonat every squaring step, so even large exponents are handled quickly and without overflow. This is the core operation behind public-key cryptography. - Congruence Check — tests whether
a ≡ b (mod n), i.e. whetheraandbleave the same remainder. Equivalently, it checks whetherndividesa − b.
Why must the modulus be non-zero?
Division by zero is undefined, and a mod 0 has no meaning, so the calculator requires a non-zero integer modulus. A negative modulus is accepted — the result is reduced against its absolute value.
Are negative exponents supported?
No. a^(-b) mod n would require the modular inverse of a, which only exists when a and n are coprime, so modular exponentiation here requires a non-negative exponent.