Modulo Calculator
Compute remainders, modular arithmetic operations, congruences, and clock math.
What Is Modulo?
The modulo operation (written as a mod m or a % m) returns the remainder when integer a is divided by integer m (the modulus). It is based on the division algorithm: for any integers a and m (m>0), there exist unique integers q (quotient) and r (remainder) such that a = q × m + r where 0 ≤ r < m.
Modular arithmetic is sometimes called clock arithmetic because of its cyclic nature — just like hours on a clock wrap around from 12 back to 1. It underpins modern cryptography (RSA, Diffie-Hellman), hash functions, checksums, cyclic data structures, and calendar calculations (what day of the week is a given date?).
Floor vs Truncated modulo: For positive numbers both give the same result. For negative numbers they differ. Python uses floor division: −7 mod 3 = 2 (always non-negative). C, Java, and JavaScript use truncated division: −7 % 3 = −1 (sign matches the dividend). Mathematically the floor version is more consistent with number theory.
Modulo vs Remainder — Negative Number Comparison
| Expression | Floor (Python) | Truncated (C/JS) |
|---|---|---|
| 17 mod 5 | 2 | 2 |
| -7 mod 3 | 2 | -1 |
| 7 mod -3 | -2 | 1 |
| -7 mod -3 | -1 | -1 |