Quick Answer
17 mod 5 = 2, because 5 goes into 17 three times (5 x 3 = 15) with a remainder of 2.
Common Examples
| Input | Result |
|---|---|
| 17 mod 5 | 2 (quotient: 3) |
| 100 mod 7 | 2 (quotient: 14) |
| 25 mod 5 | 0 (quotient: 5, divides evenly) |
| 10 mod 3 | 1 (quotient: 3) |
| 123 mod 10 | 3 (quotient: 12) |
How It Works
The Formula
The modulo operation finds the remainder after integer division. Given a dividend a and a divisor b:
a mod b = a - b x floor(a / b)
Equivalently, the division algorithm states:
a = b x q + r
| where q is the quotient (the integer part of a / b) and r is the remainder (the modulo result), with 0 <= r < | b | . |
How Modulo Works
The modulo operation answers: “after dividing a by b as many whole times as possible, what is left over?” For example:
- 17 mod 5: 5 fits into 17 three times (5 x 3 = 15), leaving 17 - 15 = 2.
- 100 mod 7: 7 fits into 100 fourteen times (7 x 14 = 98), leaving 100 - 98 = 2.
- 25 mod 5: 5 fits into 25 exactly five times (5 x 5 = 25), leaving 0.
When the remainder is 0, the divisor divides the dividend evenly. This is the basis for divisibility tests.
Modulo with Negative Numbers
For negative dividends, this calculator uses truncated division (the same behavior as the % operator in JavaScript, C, and Java). The quotient is truncated toward zero, and the remainder has the same sign as the dividend. For example, -17 mod 5 = -2 because the quotient is -3 (truncated from -3.4).
Worked Example
To compute 123 mod 10: divide 123 by 10 to get 12.3. The integer quotient is 12. Multiply back: 10 x 12 = 120. Subtract: 123 - 120 = 3. So 123 mod 10 = 3. Verification: 10 x 12 + 3 = 123.
To compute 100 mod 7: divide 100 by 7 to get 14.2857. The integer quotient is 14. Multiply back: 7 x 14 = 98. Subtract: 100 - 98 = 2. So 100 mod 7 = 2. Verification: 7 x 14 + 2 = 100.
CalculateY