Modulo Calculator
The remainder and quotient when dividing one integer by another.
Input sheet
DIY at your own risk. Calcora's calculators and guides are general estimates and information only — not professional, engineering, legal, or safety advice. Always verify local building codes and permit requirements, and hire a licensed pro for electrical, gas, plumbing, structural, or any work you're not fully comfortable doing yourself.
The modulo operation returns the remainder left over after dividing one integer by another. It's a workhorse in programming — used for cycling through values, checking divisibility, hashing, and wrapping clocks and calendars.
How it works
a mod b is the remainder after dividing a by b: remainder = a − ⌊a ÷ b⌋ × b.
Dividing a by b gives a whole-number quotient and a leftover remainder. The quotient here is the floor (rounded down toward negative infinity), and the remainder is whatever's left after multiplying that quotient back by the divisor: remainder = a − ⌊a ÷ b⌋ × b.
Using the floor for the quotient means the remainder always carries the same sign as the divisor, which keeps results consistent and is the behavior most useful for wrap-around logic. This is why a negative dividend can still produce a positive remainder when the divisor is positive.
a mod b = a − ⌊a ÷ b⌋ × b, where ⌊a ÷ b⌋ is the quotient rounded down (floor).
Worked examples
17 mod 5. → Remainder 2 (quotient 3)
⌊17 ÷ 5⌋ = 3, and 17 − 3 × 5 = 17 − 15 = 2.
−7 mod 3, showing floored-division behavior. → Remainder 2 (quotient −3)
⌊−7 ÷ 3⌋ = −3 (rounded down), and −7 − (−3 × 3) = −7 + 9 = 2.
Tips & gotchas
- Use modulo to test divisibility: if a mod b is 0, then a divides evenly by b.
- For cyclic patterns — days of the week, clock hours, array indices — modulo by the cycle length wraps values neatly back to the start.
- Be deliberate with negative numbers: this calculator floors the quotient, so the remainder takes the divisor's sign, which can differ from the truncated remainder some languages use.
- A divisor of zero is undefined — you can't take a remainder when dividing by nothing.
FAQ
How is modulo different from regular division?
Division gives you the quotient (how many times one number fits into another); modulo gives you what's left over after that division.
Why can a negative dividend give a positive remainder?
Because the quotient is floored (rounded down), the remainder ends up sharing the divisor's sign — so −7 mod 3 is 2, not −1.
What does a remainder of zero mean?
It means b divides a exactly with nothing left over, so a is a multiple of b.
Related calculators
Percentage Calculator · Percent Change Calculator · Average (Mean) Calculator · Ratio Calculator · Exponent Calculator