Modulo Calculator
Remainder after division
About This Calculator
The modulo operation returns the remainder after integer division of one number by another. It is widely used in programming for cyclic operations, determining even/odd numbers, clock arithmetic, and cryptography. The result of a mod m is always between 0 and m−1.
Formula
a mod m = a − m × floor(a / m)
Equivalently: the remainder when a is divided by m
Example Calculation
Find 17 mod 5.
- 17 ÷ 5 = 3 remainder 2 (since 3 × 5 = 15)
- 17 − 15 = 2
17 mod 5 = 2
Modulo Results (a mod m)
| a | mod 2 | mod 3 | mod 5 | mod 7 | mod 10 |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 1 | 1 | 1 |
| 2 | 0 | 2 | 2 | 2 | 2 |
| 3 | 1 | 0 | 3 | 3 | 3 |
| 4 | 0 | 1 | 4 | 4 | 4 |
| 5 | 1 | 2 | 0 | 5 | 5 |
| 6 | 0 | 0 | 1 | 6 | 6 |
| 7 | 1 | 1 | 2 | 0 | 7 |
Frequently Asked Questions
What is the modulo operator used for in programming?
Common uses include checking if a number is even (n mod 2 == 0), cycling through an array index (i mod length), and implementing clock or calendar arithmetic.
How does modulo work with negative numbers?
Results differ by language. In Python, −7 mod 3 = 2 (always non-negative). In C/Java, −7 % 3 = −1 (same sign as the dividend). Check your language's definition.
Is modulo the same as the remainder?
For positive numbers, yes. They differ for negative numbers depending on rounding direction. Python's modulo always returns a non-negative result for positive divisors.