Calculateus

Modulo Calculator

Calculate the remainder when one number is divided by another (a mod b).

Result

a mod b
2
Quotient (floor)
3

Uses the mathematical (floored) definition of modulo, which always returns a result with the same sign as the divisor - this can differ from the % operator's behavior in some programming languages for negative numbers.

About the Modulo Calculator

The modulo operation returns the remainder left over after division, and it quietly powers everything from clock arithmetic to programming loops and cryptography. Our Modulo Calculator finds a mod b instantly, along with the floored quotient used to get there.

How It Works

You enter a dividend (a) and a divisor (b), and the calculator returns the remainder after dividing a by b, using the mathematical floored definition of modulo rather than a simple truncated one.

a mod b = a − b × floor(a ÷ b)

Formula & Methodology

Floored modulo works by first finding the floor of a ÷ b, the largest integer that is not greater than the true quotient, then multiplying that floor back by b and subtracting the result from a. What's left over is the remainder. This definition guarantees the result always carries the same sign as the divisor, which is the convention used in mathematics and in languages like Python. It differs from the 'truncated' modulo used by some other programming languages, where the remainder instead takes the sign of the dividend. The two definitions agree completely for positive inputs and only diverge when either a or b is negative, at which point the results can differ by exactly the divisor's magnitude.

Step-by-Step: Calculating It By Hand

  1. 1Divide a by b to get the true (possibly fractional) quotient.
  2. 2Take the floor of that quotient, rounding down toward negative infinity.
  3. 3Multiply the floored quotient by b.
  4. 4Subtract that product from a to get the remainder, a mod b.

Examples

Simple remainder

17 mod 5 = 2, since 5 divides into 17 three times (15) with 2 left over.

Negative dividend

−7 mod 3 = 2 under the floored definition, because floor(−7 ÷ 3) = −3, and −7 − (3 × −3) = 2.

Advantages

  • Uses the consistent, mathematically standard floored definition of modulo
  • Shows both the remainder and the floored quotient used to compute it
  • Handles negative dividends and divisors correctly
  • Faster and more reliable than working it out by hand for negative or large numbers

Common Mistakes

  • Assuming this always matches a programming language's % operator, which may use truncated modulo instead
  • Forgetting that modulo by zero is undefined and will not return a numeric result
  • Expecting a negative remainder when the divisor is positive, which floored modulo never produces
  • Mixing up quotient and remainder when checking results by hand

Edge Cases to Watch For

  • Modulo by zero is undefined, since it requires dividing by zero to find the quotient.
  • With a negative divisor, the floored remainder takes the sign of the divisor, which can look unfamiliar if you're used to a calculator's % key using truncated modulo instead.
  • When a is an exact multiple of b, the remainder is always exactly zero regardless of sign.

Common Use Cases

  • Programming logic that depends on remainders, such as alternating patterns or wraparound indexing
  • Clock and calendar arithmetic, like figuring out what day of the week a date falls on
  • Checking divisibility (a mod b = 0 means b divides a evenly)
  • Cryptography and hashing, where modulo operations are fundamental building blocks
Written & fact-checked by the Calculateus TeamLast updated August 5, 2026How we verify our formulas

Frequently asked questions

Why might this differ from my calculator's % button?

Some tools use "truncated" modulo (result takes the sign of the dividend), while this uses the mathematical "floored" modulo (result takes the sign of the divisor) - they agree for positive numbers but can differ by exactly the divisor's value when either input is negative.

Conclusion

Once you see modulo as 'what's left over,' the formula becomes intuitive even when negative numbers make it feel tricky. If you only need to confirm whether one number evenly divides another, our GCF & LCM Calculator can help with related divisibility questions.