Remainder versus true modulo
When you divide a by n, the leftover amount is the remainder. The two results this tool reports agree perfectly for non-negative dividends, but they diverge once a is negative.
The signed remainder keeps the sign of the dividend, which is how the % operator behaves in most programming languages. The true modulo instead always lands in the range 0 to n−1, matching the mathematical definition used in number theory.
- Signed remainder: same sign as a, so −7 % 3 = −1.
- True modulo: always non-negative, so −7 mod 3 = 2.
- The two differ by exactly n whenever the signed result is negative.
Reading the result
Pick the value that fits your problem. If you are wrapping around a fixed cycle — clock hours, days of the week, or an array index — you almost always want the true modulo, because a negative index or hour makes no sense.
If you are mirroring the exact behaviour of code that uses the % operator, read the signed remainder so your hand calculation matches the program.
Practical uses
Modulo is the backbone of any cyclic or periodic calculation, and it shows up far beyond math homework.
- Test evenness: a mod 2 is 0 for even numbers.
- Wrap clock arithmetic: (hour + shift) mod 12.
- Distribute items into buckets or hash keys evenly.
Common mistakes
The biggest trap is assuming the % operator always returns a positive value. With negative inputs it does not, which can produce out-of-range indices or off-by-one cycle errors.
- A divisor of zero is undefined and is rejected.
- Do not assume a % n is non-negative when a can be negative.
- For fractional inputs the remainder is also fractional, not just whole numbers.
Formula
remainder = a % n; true modulo = ((a % n) + n) % nFrequently asked questions
- Which one should I use for clock-style wraparound?
- The true modulo, since it never returns a negative value — ideal for hours, days of week and array indices.

