mod

Modulo Calculator

Find the remainder when a is divided by b — with step-by-step explanation.

Results

What Is the Modulo Operation?

The modulo operation (written as a mod b or a % b) returns the remainder when integer a is divided by integer b. It is one of the most fundamental operations in mathematics and computer science. The result is always between 0 and |b| − 1 for positive divisors.

How to Calculate a Mod b

Divide a by b and find the remainder: a mod b = a − b × floor(a/b). For example, 17 mod 5: 17 ÷ 5 = 3 remainder 2, so 17 mod 5 = 2. Verification: 5 × 3 + 2 = 17 ✓.

Negative Numbers and Modulo

For negative numbers, the result depends on the convention. In mathematics, the result has the same sign as the divisor (floored division). In many programming languages (C, Java), it has the same sign as the dividend (truncated division). This calculator uses the mathematical (floor) convention.

Applications of Modulo

Modulo is ubiquitous in computing: determining if a number is even or odd (n mod 2 = 0 for even), cycling through array indices (index mod length), clock arithmetic (12-hour clock wraps at 12), hashing functions, cryptography (RSA encryption uses modular arithmetic), and generating repeating patterns.

Modular Arithmetic

Two numbers are congruent modulo m if they have the same remainder when divided by m: a ≡ b (mod m). Clock arithmetic is modulo 12: 10 + 4 = 14 ≡ 2 (mod 12), meaning 10 hours after 10am is 2pm.

Worked Example: Day of the Week Calculator

Suppose today is Wednesday (day 3, where Sunday = 0). What day will it be 100 days from now?

New day = (3 + 100) mod 7 = 103 mod 7.

103 ÷ 7 = 14 with remainder 5. So 103 mod 7 = 5.

Day 5 is Friday. So 100 days after Wednesday is a Friday. This illustrates modular arithmetic for cyclic calendar problems.

Common Modulo Results Reference

aba mod bInterpretation
103110 = 3×3 + 1
154315 = 4×3 + 3
10072100 = 7×14 + 2
256160256 is divisible by 16

Frequently Asked Questions

10 ÷ 3 = 3 remainder 1, so 10 mod 3 = 1.

For positive numbers they are the same. For negative numbers, remainder keeps the sign of the dividend, while modulo keeps the sign of the divisor. Example: −7 mod 3 = 2 (mathematical modulo) vs. −7 remainder 3 = −1 (truncated).

Yes. Any integer where n mod 2 = 0 is even; if n mod 2 = 1, it is odd.

0 mod 5 = 0. Zero divided by any non-zero number has remainder 0.

Common uses: checking parity (even/odd), wrapping array indices, limiting values to a range, generating hash values, and implementing cyclic structures like round-robin scheduling.

Modular exponentiation computes (base^exponent) mod m efficiently. It is fundamental to RSA cryptography. For example, 3⁴ mod 5 = 81 mod 5 = 1. Rather than computing 3⁴ = 81 first, you can reduce at each step: (3² mod 5)² mod 5 = (9 mod 5)² mod 5 = 4² mod 5 = 16 mod 5 = 1.

No. For any non-zero integer n, n mod n = 0 because n divides exactly once with no remainder. For example, 7 mod 7 = 0, 100 mod 100 = 0. Only if you mod by a divisor will you get 0 — otherwise the result is between 1 and (divisor − 1).

Formula sources & accuracy standards: Calculator Methodology · Editorial Policy