Modulo Calculator
Calculate the modulo (remainder) when one number is divided by another. Essential for programming, clock arithmetic, and number theory.
Modulo Arithmetic Guide
What is Modulo?
The modulo operation (written a mod n or a % n in programming) gives the remainder after dividing a by n. 17 mod 5 = 2, because 17 = 5×3 + 2. 20 mod 4 = 0 (20 is exactly divisible by 4). 7 mod 7 = 0. For any integer a and positive n: a mod n is always between 0 and n-1. The modulo operation is fundamentally different from division — it discards the quotient and keeps only the remainder.
Negative Numbers and Modulo
Different programming languages handle negative modulo differently. In Python: -7 mod 3 = 2 (mathematical/floored modulo — always non-negative). In C, Java, JavaScript: -7 % 3 = -1 (truncated remainder — takes sign of dividend). The mathematical definition (result always non-negative) is generally more useful. -7 mod 3 = 2 because -7 = 3×(-3) + 2. This calculator uses the mathematical (non-negative) convention.
Modular Arithmetic Applications
Clock arithmetic: 'It is 10am, what time will it be in 15 hours?' → (10 + 15) mod 24 = 1am. Days of the week: day 0 = Sunday, if today is Wednesday (day 3), what day is it in 100 days? → (3 + 100) mod 7 = 5 = Friday. Calendar calculations: any repeating cycle uses modulo. Cryptography: RSA encryption is based on modular exponentiation. Checksums: IBAN bank account validation, ISBN book number checks.
In Programming
The % operator in most programming languages gives the remainder (modulo). Checking if a number is even: n % 2 == 0. Checking if a number is divisible by k: n % k == 0. Wrapping around an array: index = (index + 1) % arrayLength. Converting between 12-hour and 24-hour time: hour12 = hour24 % 12 || 12. Generating a hash that fits in a table of size n: hash = value % n. Modulo is one of the most frequently used operations in programming.
Recommended for this calculator