Modulo Calculator
What modulo means
For positive numbers, modulo is simply the remainder: divide a by b, throw away the quotient, keep what is left. Formally, a mod b = a − b × floor(a ÷ b), and the result always satisfies a = q × b + r with 0 ≤ r < b (for positive b). That identity is the whole subject in one line: any integer splits into a whole number of b’s plus a leftover smaller than b.
Modulo is why clock arithmetic works — 15:00 is 3 p.m. because 15 mod 12 = 3 — why a weekday cycles every 7 days, why the last digit of a number is the number mod 10, and why checksums like the ISBN and IBAN mod-97 test can catch a mistyped digit. Our IBAN Validator uses exactly that mod-97 arithmetic. Even the schoolroom divisibility tests are modulo in disguise: a number is divisible by 9 exactly when the sum of its digits is, because both leave the same remainder mod 9 — the old “casting out nines”.
The two conventions: floored vs truncated
Everything is easy until a negative number appears, because then “what is left over” depends on which way you round the division. Truncated division rounds toward zero: −17 ÷ 5 = −3.4 truncates to −3, leaving −17 = (−3) × 5 + (−2), so the remainder is −2. This is what the % operator does in C, C++, Java, C# and JavaScript, and it gives a result with the sign of the dividend. Floored division rounds toward negative infinity: −17 ÷ 5 floors to −4, leaving −17 = (−4) × 5 + 3, so the modulo is 3. This is the mathematician’s convention, and what Python’s % and this calculator’s main result use: for a positive divisor the answer always lands in 0 ≤ r < b.
Which one do you need? For mathematics, cryptography, calendars and anything cyclic — weekdays, clock times, hash buckets, “every nth item” logic — the floored result is almost always the one that behaves: −17 mod 5 = 3 correctly says that −17 sits in the same cycle position as 3, 8, 13 and 23. For matching a program’s output in a truncated-division language, you need the other one, which is why both are shown above with their quotients, so you can see exactly which identity each belongs to.
Worked examples
17 mod 5 = 2: 17 ÷ 5 = 3.4, floor 3; 17 − 3 × 5 = 2. Check: 3 × 5 + 2 = 17. ✓
−17 mod 5 = 3 (floored) / −2 (truncated): floored, −17 ÷ 5 = −3.4 floors to −4; −17 − (−4 × 5) = 3, and −4 × 5 + 3 = −17 ✓. Truncated, the quotient is −3 and the remainder −2: −3 × 5 + (−2) = −17 ✓. Both identities check out — they are answers to two slightly different questions.
123,456 mod 97 = 72: 97 × 1,272 = 123,384, and 123,456 − 123,384 = 72. Large-number modulo like this is the engine inside check-digit systems and hashing; note that you never need the full division, only the leftover.
Decimals work too: 17.5 mod 2.5 = 0, because 17.5 is exactly 7 × 2.5. The calculator accepts decimal inputs and applies the same floored formula.
Frequently asked questions
What is 17 mod 5?
2. Seventeen divides into three complete groups of five (15) with 2 left over: 17 = 3 × 5 + 2. That leftover is the modulo. The same pattern runs clock arithmetic (17 mod 12 = 5, so 17:00 is 5 p.m.) and weekday cycles (17 mod 7 = 3, so 17 days from Monday is a Thursday). Whenever only the position inside a repeating cycle matters, modulo is the tool.
Why does my programming language give a different answer for negative numbers?
Because most languages’ % operator is a remainder, not a true modulo. C, Java, JavaScript and their relatives truncate the division toward zero, so −17 % 5 returns −2, keeping the sign of the dividend. Mathematics and Python floor the division instead, so −17 mod 5 = 3, keeping the sign of the divisor and always landing between 0 and the divisor. Neither is a bug — they are two conventions — and this calculator shows both so you can match the one your code or your maths course uses.
What happens when you mod by zero?
It is undefined, for the same reason division by zero is undefined: there is no quotient and no leftover when you try to split something into groups of zero. Programs typically return NaN or throw an error. The calculator will tell you the divisor must not be zero rather than invent a number. Modding zero itself is fine, by contrast: 0 mod 5 = 0, because zero divides into zero groups with nothing left.
Where is modulo used in real life?
Everywhere cycles repeat: clocks (mod 12 and 24), calendars (mod 7 for weekdays, mod 4 for leap years), check digits on bank accounts, cards and ISBNs (mod 97 and mod 10), hash tables that spread keys across a fixed number of buckets, computer graphics wrapping textures, and public-key cryptography, where arithmetic on enormous numbers is done mod a prime. The parity test is the simplest case: n mod 2 = 0 means even, 1 means odd.
Can modulo work with decimal numbers?
Yes. The floored definition a − b × floor(a ÷ b) works for any real numbers with b ≠ 0: 17.5 mod 2.5 = 0 because 17.5 is exactly seven lots of 2.5, and 7.25 mod 2 = 1.25. One caution from computing: decimals are stored as binary fractions, so results like 0.3 mod 0.1 can come back as 0.0999… rather than a clean 0 — a floating-point artefact, not a maths error.
Related tools
Worked examples verified in Node on 24 November 2026. Everything is calculated in your browser — nothing you type is sent anywhere.