What a mod n means
a mod n is the remainder after dividing a by n. Write a = n × q + r, where q is a whole number (the quotient) and r is the remainder.
Floored: q = floor(a ÷ n), r takes the sign of n
Truncated: q = a ÷ n rounded toward 0, r takes the sign of a
Euclidean: 0 ≤ r < |n|
For positive numbers all three give the same answer. They differ when a or n is negative. Math books and Python's % use the floored version, which matches modular arithmetic: −7 mod 3 = 2. JavaScript, C and Java's % operator truncates instead, so −7 % 3 is −1. The calculator shows all three so you can match whichever one you need.
Worked examples
17 mod 5: 17 ÷ 5 = 3.4, so q = 3. Then 17 − 5 × 3 = 17 − 15 = 2.
−7 mod 3: −7 ÷ 3 = −2.33. Floored, q = −3 and r = −7 − 3 × (−3) = −7 + 9 = 2. Truncated, q = −2 and r = −7 − 3 × (−2) = −1. Both are correct under their own rule, and they differ by exactly 3.
Big numbers: 2¹⁰⁰ = 1,267,650,600,228,229,401,496,703,205,376. Since 2³ = 8 = 7 + 1, every third power of 2 is 1 more than a multiple of 7, and 2¹⁰⁰ = 2 × (2³)³³. So 2¹⁰⁰ mod 7 = 2. The calculator uses exact big-integer arithmetic, so it gets this from all 31 digits without rounding.
Where mod is used
- Clock time: 15:00 is 15 mod 12 = 3 o'clock. 100 hours from now is 100 mod 24 = 4 hours later on the clock, 4 days on.
- Days of the week: 30 days after a Monday is 30 mod 7 = 2 days later, a Wednesday.
- Even and odd: n mod 2 is 0 for even numbers and 1 for odd ones.
- Programming: wrapping around a list, alternating rows, check digits and hashing.
Limitations
- mod 0 isn't defined, just like division by 0.
- Numbers can have up to 5,000 digits. Decimals are handled exactly too, using the same rules: 5.5 mod 2 = 1.5.
- Spreadsheets differ: Excel's MOD follows the floored rule (the result has the sign of the divisor).