Skip to content
Calcora

Modulo Calculator

The remainder and quotient when dividing one integer by another.

Input sheet

Browse DIY guidesDo the project yourself, step by step

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

Tips & gotchas

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