Modulo Calculator (a mod b, Remainder & Quotient)
The modulo operation gives the remainder left after dividing one number by another, the basis of clock arithmetic, check digits and cyclic counters. This modulo calculator returns a mod b, the integer quotient and the remainder, and shows how the result differs for negative numbers between mathematical (floored) modulo and the truncated remainder of C, Java and JavaScript.
How to use the modulo calculator
Enter the dividend a and the divisor b. The calculator returns the floored quotient, a mod b (the mathematical modulo, which always has the sign of b) and the truncated remainder that the % operator gives in C-family languages. For positive numbers the two are the same.
Modulo formula
a mod b = a − b × ⌊a ÷ b⌋ · truncated remainder = a − b × trunc(a ÷ b)
Worked example
17 mod 5:
- 17 ÷ 5 = 3.4, so the quotient is 3
- 17 − 5 × 3 = 2, so 17 mod 5 = 2
Floored vs truncated
| a | b | ⌊a/b⌋ | a mod b (floored) | a % b (truncated) |
|---|---|---|---|---|
| 17 | 5 | 3 | 2 | 2 |
| -17 | 5 | -4 | 3 | -2 |
| 17 | -5 | -4 | -3 | 2 |
| -17 | -5 | 3 | -2 | -2 |
| 100 | 7 | 14 | 2 | 2 |
| 2026 | 12 | 168 | 10 | 10 |
| 5.5 | 2 | 2 | 1.5 | 1.5 |
Uses of modular arithmetic
- Clock time — 15:00 + 10 hours = 25 mod 24 = 01:00.
- Even and odd — n mod 2 is 0 for even numbers, 1 for odd.
- Check digits — ISBN-10 uses mod 11, IBAN uses mod 97.
- Cyclic counters and ring buffers — index = (index + 1) mod size.
Frequently asked questions
What is a mod b?
The remainder after dividing a by b, so that a = b × q + (a mod b). For example 17 mod 5 = 2, because 17 = 5 × 3 + 2.
What is −17 mod 5?
In mathematics (floored division) it is 3, because −17 = 5 × (−4) + 3. In C, Java and JavaScript, −17 % 5 gives −2, because they truncate the quotient towards zero.
Which languages use floored modulo?
Python's %, Ruby, and spreadsheet MOD() return a result with the sign of the divisor (floored). C, C++, Java, JavaScript and C# return a result with the sign of the dividend (truncated).
Can modulo be used with decimals?
Yes. 5.5 mod 2 = 1.5. Floating-point rounding can make results like 0.3 mod 0.1 come out very slightly off zero.