Modulo Calculator

Calculate the remainder when dividing one number by another. Used in programming, cryptography, and modular arithmetic.

#

Enter your values above to see the results.

Tips & Notes

  • mod b always gives a result between 0 and b-1 inclusive. 17 mod 5 = 2 (remainder when 17 is divided by 5). Quick check: 5×3=15, leftover=2. The result can never equal or exceed b.
  • Divisibility test: a mod b = 0 means b divides a evenly. 144 mod 12 = 0 confirms 12 divides 144. 145 mod 12 = 1 confirms 12 does not divide 145. Faster than long division for quick checks.
  • Cyclic indexing: wrapping around a list of n items uses mod n. Array index = position mod length. If array has 7 items and you want item 10, use index 10 mod 7 = 3.
  • Day-of-week calculation: add days to a base weekday number (0=Sun through 6=Sat), then mod 7. Wednesday is 3, add 18 days: (3+18) mod 7 = 21 mod 7 = 0 = Sunday.
  • Even/odd detection: n mod 2 = 0 means even, n mod 2 = 1 means odd. This is how every programming language checks parity and it is the simplest modulo application.
  • Negative numbers: mathematical modulo is always non-negative, but language implementations differ. In Python, -7 mod 3 = 2. In C/Java, -7 % 3 = -1. Be aware which convention your environment uses.

Common Mistakes

  • Confusing modulo with remainder for negative numbers. Mathematical mod always returns a non-negative result: -7 mod 3 = 2 (not -1). Some programming languages use truncated division instead, giving negative remainders.
  • Reversing dividend and divisor: a mod b and b mod a give different results. 7 mod 3 = 1 (7 divided by 3), but 3 mod 7 = 3 (3 divided by 7, quotient 0, remainder 3).
  • Division by zero: a mod 0 is undefined for the same reason a/0 is undefined. If b=0, the operation has no meaning.
  • Forgetting the result range: a mod b produces values 0 through b-1, never b itself. If you get b as a result, the divisor was used as dividend by mistake.
  • Using modulo when integer division (quotient) is needed. 17 mod 5 = 2 gives the remainder. 17 div 5 = 3 gives the quotient. These answer different questions.
  • Assuming a mod b = 0 means a = b. It means a is a multiple of b. 144 mod 12 = 0 because 144 = 12×12, not because 144 = 12.

Modulo Calculator Overview

The modulo operation returns the remainder after integer division — the "leftover" amount when one number is divided by another as evenly as possible. Written as a mod b or a % b, it always produces a result between 0 and b−1 (for positive b). Modulo is one of the most frequently used operations in computer programming, underlying hash tables, cyclic data structures, cryptographic algorithms, and every clock or calendar calculation involving wrap-around counting.

The defining relationship:

a mod b = r, where a = q×b + r and 0 ≤ r < b (q is the quotient, r is the remainder)
EX: 17 mod 5 → 17 = 3×5 + 2 → remainder = 2 | 100 mod 7 → 100 = 14×7 + 2 → remainder = 2
Divisibility check: a mod b = 0 means b divides a exactly with no remainder — the cleanest and most common use:
EX: Is 144 divisible by 12? → 144 mod 12 = 0 ✓ | Is 145 divisible by 12? → 145 mod 12 = 1 ✗
Clock arithmetic — numbers that wrap around at a fixed modulus:
EX: It is 10:00. What time is it 27 hours later? → (10+27) mod 24 = 37 mod 24 = 13 → 1:00 PM
EX: Today is Wednesday (day 3 of week). What day is it in 100 days? → (3+100) mod 7 = 103 mod 7 = 5 → Friday
Negative number behavior: mathematical modulo always returns non-negative results (−7 mod 3 = 2). Many programming languages return a negative remainder matching the dividend's sign (−7 % 3 = −1 in C, Java). Python follows the mathematical convention: −7 % 3 = 2. Diffie-Hellman key exchange similarly relies on modular arithmetic. Every HTTPS connection you make uses mod operations hundreds of times per second. Luhn algorithm (credit card validation): sum digits with alternating doubling, take result mod 10. If result = 0, the card number is valid. This is why card numbers can be partially verified without knowing the full account. Modular arithmetic creates finite number systems where arithmetic wraps around predictably.

Frequently Asked Questions

The modulo operation finds the remainder after integer division. 17 mod 5: divide 17 by 5 = 3 remainder 2, so 17 mod 5 = 2. General rule: a mod b = a − b × floor(a/b). Example: 23 mod 7 = 23 − 7×3 = 23 − 21 = 2. The result is always between 0 and b−1 inclusive. Modulo checks divisibility: a mod b = 0 means b divides a evenly. 24 mod 6 = 0 confirms 6 divides 24.

Computers use modulo constantly for index wrapping, hashing, and cyclic structures. Array index wrapping: index mod array_length keeps indices within bounds — useful for circular buffers and round-robin scheduling. Hash functions: key mod table_size maps any key to a valid array index. Clock arithmetic: (current_hour + hours_added) mod 24 gives the new hour on a 24-hour clock. Color cycling in graphics, music rhythm patterns, and pseudorandom number generators all rely on modulo.

The day-of-week calculation uses modulo 7. Given a date's total day number (days since a fixed reference), day_of_week = day_number mod 7, where 0=Sunday through 6=Saturday (or 1=Monday, etc.). Zeller's congruence uses this approach. Example: January 1, 2000 was a Saturday (day 6). 100 days later: 6 + 100 = 106. 106 mod 7 = 1 → Monday. Modulo makes cyclic calendar arithmetic simple without tracking full week counts.

Modulo arithmetic obeys addition, subtraction, and multiplication rules. (a + b) mod m = ((a mod m) + (b mod m)) mod m. Example: (17 + 8) mod 5 = 25 mod 5 = 0. Check: (17 mod 5) + (8 mod 5) = 2 + 3 = 5, then 5 mod 5 = 0 ✓. This lets you compute modulo of very large numbers by reducing intermediate results at each step, avoiding overflow. RSA encryption uses modular exponentiation for exactly this reason.

The behavior of negative numbers in modulo differs across programming languages. In Python, (−7) mod 3 = 2 (result has the sign of the divisor). In C, Java, and JavaScript, (−7) % 3 = −1 (result has the sign of the dividend). Mathematically, the positive result (2) is more consistent with modular arithmetic theory because −7 = 3×(−3) + 2, giving remainder 2. Always check your language's convention when using negative values in modulo operations.

A number is divisible by 9 if and only if its digit sum is divisible by 9 — provable with modulo. Each decimal digit position represents a power of 10, and 10 mod 9 = 1, so 10ⁿ mod 9 = 1 for all n. Therefore any number equals its digit sum modulo 9. Example: 738 = 7+3+8 = 18, and 18 mod 9 = 0, so 738 is divisible by 9. Verify: 738/9 = 82 ✓. The same logic gives the divisibility rule for 3 (digit sum divisible by 3).