➗ Modulo Calculator
By ToolNimba Team · Updated 2026-06-19
Enter a dividend and a divisor to see the result.
The modulo operation returns the remainder left over after dividing one number by another. This calculator takes a dividend (a) and a divisor (n) and instantly shows a mod n, the quotient, and the always-positive mathematical modulo.
It also makes the tricky part clear: how negative numbers behave. Programming languages and pure mathematics do not always agree on the sign of a remainder, so the tool shows both the truncated remainder (the way most languages compute it) and the non-negative result you get with the wrap-around formula.
What is the Modulo Calculator?
Modulo, often written as a mod n or with the percent sign in code, is the remainder you are left with after integer division. If you divide 17 by 5 you get 3 with 2 left over, so 17 mod 5 equals 2. The quotient is 3 and the remainder is 2. Modulo only cares about that remainder, which is why it is the backbone of tasks like wrapping a value into a fixed range, checking divisibility, and computing cyclic positions such as days of the week or hours on a clock.
The subtle part is negative numbers. There are two common conventions. The truncated convention divides toward zero and gives the remainder the same sign as the dividend, so -17 mod 5 comes out as -2. This is what the percent operator does in many languages including JavaScript, C, and Java. The mathematical or floored convention always returns a result between zero and the divisor, so -17 mod 5 comes out as 3. You can convert a truncated result to the non-negative version with the formula shown below.
This calculator reports both so there is no ambiguity. It also handles the special case of a divisor of zero, which is undefined because dividing by zero has no meaning. Decimal inputs are accepted as well, in which case the remainder is the fractional amount left after subtracting whole multiples of the divisor.
When to use it
- Checking whether a number is even, odd, or divisible by another number (a mod n equals 0 means n divides a evenly).
- Wrapping an index or counter back into a fixed range, such as cycling through colors in a list or pages in a carousel.
- Converting between 24-hour and 12-hour clock times, or computing what hour it will be after a number of hours pass.
- Working out which day of the week a future date falls on by taking the day count modulo 7.
- Verifying answers in modular arithmetic homework and understanding why negative results differ between math and code.
- Distributing items evenly into buckets and finding the leftover after the last full group.
How to use the Modulo Calculator
- Enter the dividend (a), the number being divided, in the first field.
- Enter the divisor (n), the number you divide by, in the second field.
- Read the remainder (a mod n) using the truncated convention used by most programming languages.
- Read the positive modulo for the non-negative mathematical result between zero and the divisor.
- Check the quotient to see how many whole times the divisor fits into the dividend.
- Try the quick example buttons to compare how positive and negative inputs change the sign of the answer.
Formula & method
Worked examples
Basic positive case: 17 mod 5.
- Divide 17 by 5 to get 3.4, then truncate toward zero to get a quotient of 3.
- Multiply the quotient by the divisor: 3 times 5 equals 15.
- Subtract from the dividend: 17 minus 15 equals 2.
Result: 17 mod 5 = 2, quotient 3. The positive modulo is also 2.
Negative dividend: -17 mod 5.
- Divide -17 by 5 to get -3.4, then truncate toward zero to get a quotient of -3.
- Multiply: -3 times 5 equals -15. Subtract: -17 minus -15 equals -2 (the truncated remainder).
- Apply the positive formula: ((-2) + 5) mod 5 equals 3.
Result: Truncated remainder -2, positive modulo 3, quotient -3.
Negative divisor: 17 mod -5.
- Divide 17 by -5 to get -3.4, then truncate toward zero to get a quotient of -3.
- Multiply: -3 times -5 equals 15. Subtract: 17 minus 15 equals 2 (the truncated remainder).
- Apply the positive formula using the absolute value of n: (2 + 5) mod 5 equals 2.
Result: Truncated remainder 2, positive modulo 2, quotient -3.
Truncated remainder versus positive modulo for sign combinations (divisor magnitude 5)
| Dividend a | Divisor n | Quotient | Truncated remainder | Positive modulo |
|---|---|---|---|---|
| 17 | 5 | 3 | 2 | 2 |
| -17 | 5 | -3 | -2 | 3 |
| 17 | -5 | -3 | 2 | 2 |
| -17 | -5 | 3 | -2 | 3 |
Common modulo results
| Expression | Quotient | Remainder |
|---|---|---|
| 10 mod 3 | 3 | 1 |
| 100 mod 7 | 14 | 2 |
| 8 mod 4 | 2 | 0 |
| 5 mod 10 | 0 | 5 |
Common mistakes to avoid
- Expecting a negative remainder to be positive. In math classes the modulo of a negative number is usually non-negative, but in JavaScript, C, and Java the percent operator returns a value with the sign of the dividend. That is why -17 percent 5 is -2 in code, not 3. Use the positive modulo formula when you need a non-negative result.
- Confusing the quotient with the remainder. The quotient is how many whole times the divisor fits in, while the remainder is what is left over. For 17 divided by 5 the quotient is 3 and the remainder is 2. Modulo gives you the remainder, not the quotient.
- Dividing by zero. A modulo with a divisor of zero is undefined because division by zero has no meaning. Most languages return NaN or throw an error, so always guard against a zero divisor.
- Assuming modulo only works on integers. Modulo is defined for decimals too. For example 5.5 mod 2 is 1.5, the amount left after subtracting whole multiples of 2. Floating point rounding can make such results slightly imprecise in code.
Glossary
- Dividend (a)
- The number being divided in the modulo operation.
- Divisor (n)
- The number you divide by, also called the modulus. It must not be zero.
- Quotient
- How many whole times the divisor fits into the dividend, here truncated toward zero.
- Remainder
- The amount left over after subtracting whole multiples of the divisor from the dividend.
- Truncated modulo
- The remainder convention where the result takes the sign of the dividend, used by many programming languages.
- Floored modulo
- The convention where the result always lies between zero and the divisor, common in pure mathematics.
Frequently asked questions
What is the modulo operation?
Modulo returns the remainder after dividing one number by another. For example, 17 mod 5 is 2 because 5 goes into 17 three times with 2 left over.
How is modulo different from division?
Division gives the quotient, how many times the divisor fits in. Modulo gives only the leftover remainder. For 17 divided by 5 the quotient is 3 and the modulo is 2.
Why does the modulo of a negative number differ between sites?
There are two conventions. The truncated one gives the remainder the sign of the dividend, so -17 mod 5 is -2. The mathematical one is always non-negative, so -17 mod 5 is 3. This tool shows both.
How do I always get a positive modulo result?
Take the truncated result, add the absolute value of the divisor, then apply modulo again: ((a mod n) plus the absolute value of n) mod the absolute value of n. The calculator does this for you.
What happens when the divisor is zero?
The result is undefined because division by zero has no meaning. The calculator reports undefined rather than a number, and most programming languages return NaN or raise an error.
Can I use decimals with modulo?
Yes. Modulo works on decimals too. For example, 5.5 mod 2 is 1.5. Keep in mind that floating point rounding can introduce tiny inaccuracies in code.