Tip: Use "Mathematical modulo" if you want results in the range 0 to |divisor|-1 for negative inputs.
What is the modulo operator?
The modulo operator finds the remainder after division. If you compute 27 % 5, the answer is 2, because 27 divided by 5 equals 5 with 2 left over. This operation is one of the most useful tools in programming, math, scheduling, and data processing.
A modulo operator calculator helps you quickly test values, especially when you work with loops, cyclic patterns, index wrapping, odd/even checks, and periodic events.
How to use this modulo calculator
- Enter the dividend (the value being divided).
- Enter the divisor (the value you divide by).
- Choose a mode:
- Remainder (%): behaves like JavaScript's
%operator. - Mathematical modulo: always returns a non-negative result for positive or negative inputs.
- Remainder (%): behaves like JavaScript's
- Click Calculate to see the answer and formula.
Modulo formula explained
Standard remainder form
The remainder can be described as:
remainder = a - b × trunc(a / b)
Here, a is the dividend, b is the divisor, and trunc means chopping off the decimal portion. This is why some languages return negative values when a is negative.
Mathematical modulo form
To force a non-negative result, you can use:
mod = ((a % |b|) + |b|) % |b|
This version is often preferred for clock arithmetic and array wrapping where negative remainders are inconvenient.
Examples
- 10 % 3 = 1
- 25 % 7 = 4
- 48 % 12 = 0 (because 48 is divisible by 12)
- -13 % 5 = -3 in remainder mode, but 2 in mathematical modulo mode
Real-world uses of modulus arithmetic
1) Even and odd checks
If n % 2 === 0, a number is even; otherwise, it is odd.
2) Time and cycle calculations
Modulo is perfect for repeating cycles such as weekdays, rotating shifts, pagination, and circular UI controls.
3) Programming and arrays
Use modulo to wrap indexes: when you move past the last item, modulo brings you back to the beginning. This is common in carousels, game loops, and ring buffers.
4) Cryptography and hashing
Many encryption and hashing algorithms depend on modular arithmetic. Even if you're not building cryptographic systems, understanding modulo can help you reason about data buckets and deterministic partitioning.
Common mistakes to avoid
- Division by zero: Modulo by zero is undefined and should always be rejected.
- Sign confusion: Different languages treat negative values differently for
%. - Assuming only integers: Some environments allow decimal remainder operations too.
- Mixing modulo and percent: Modulo is not a percentage; it returns a remainder.
Quick FAQ
Is modulo the same as remainder?
In casual conversation, yes. In strict math/programming contexts, they can differ for negative numbers.
Can I use decimals in this calculator?
Yes. This tool supports decimal input, though modulo is most often used with integers.
Why is modulo important for beginners?
It appears everywhere: loop logic, algorithms, date math, pattern detection, and interview problems. Mastering it early gives you a strong foundation in computational thinking.