Modulo Calculator
Find a mod n — the remainder of a ÷ n — with the quotient and a worked breakdown.
Quotient ⌊17 ÷ 5⌋ = 3, remainder = 2. Uses the mathematical convention, so the remainder is always 0 ≤ r < 5 (non-negative even when a is negative — unlike JavaScript’s % operator).
The modulo a mod n is the remainder left after dividing a by n. To find it, take the largest whole-number multiple of n that fits inside a and subtract it. For 17 mod 5, the largest multiple of 5 not exceeding 17 is 15 (= 3 × 5), so 17 mod 5 = 17 − 15 = 2, because 17 = 3 × 5 + 2.
What modulo means
When you divide an integer a (the dividend) by an integer n (the divisor or modulus), you get a whole-number quotient q and a leftover remainder r. The modulo operation, written a mod n, returns that remainder. It satisfies a = q × n + r, where q is the floor of a ÷ n and r sits in the range 0 ≤ r < n. Because the remainder can never reach n, the result of a mod n always lands somewhere between 0 and n − 1.
⌊x⌋ is the floor — the largest integer not greater than x; n must be non-zero
Worked example
Compute 17 mod 5:
- 1 Divide a by n. 17 ÷ 5 = 3.4, so the floor quotient is ⌊3.4⌋ = 3.
- 2 Multiply the quotient back by n. 3 × 5 = 15 — the largest multiple of 5 that fits inside 17.
- 3 Subtract to get the remainder. 17 − 15 = 2, so the remainder r = 2.
- 4 Confirm the division statement. 17 = 3 × 5 + 2, so 17 mod 5 = 2.
Modulo examples
Each row uses the mathematical convention, where the remainder is always 0 ≤ r < n.
| Expression | a = q × n + r | Result | Use |
|---|---|---|---|
| 17 mod 5 | 17 = 3 × 5 + 2 | 2 | Plain remainder |
| −1 mod 5 | −1 = (−1) × 5 + 4 | 4 | Negative dividend (≠ JS −1) |
| 8 mod 2 | 8 = 4 × 2 + 0 | 0 | Even number |
| 7 mod 2 | 7 = 3 × 2 + 1 | 1 | Odd number |
| 15 mod 12 | 15 = 1 × 12 + 3 | 3 | Clock arithmetic (3 o’clock) |
| 25 mod 12 | 25 = 2 × 12 + 1 | 1 | Clock arithmetic (1 o’clock) |
Where modulo is used — and the negative-number catch
Even and odd. A number is even exactly when n mod 2 = 0 and odd when n mod 2 = 1. This parity check is the most common everyday use of modulo.
Clocks and cyclic counting. Modulo wraps numbers into a repeating cycle. A 12-hour clock is arithmetic mod 12: 15 mod 12 = 3, so 15:00 reads as 3 o’clock. The same idea covers days of the week (mod 7), angles (mod 360°), and any periodic schedule.
Hashing and indexing. Hash tables and round-robin schemes map a large key down to a fixed number of buckets with key mod size, guaranteeing an index inside the valid range.
The negative-number convention. This calculator uses the mathematical convention, where the remainder is always non-negative: −1 mod 5 = 4, computed via ((a % n) + n) % n. Many programming languages disagree. JavaScript’s % operator keeps the sign of the dividend, so -1 % 5 evaluates to -1, not 4 — a frequent source of bugs when wrapping indices. If you need a guaranteed non-negative result in code, wrap the language’s % with ((a % n) + n) % n.