Modulo Calculator
Calculate the remainder after dividing any number by a divisor (the modulo operation). Enter any dividend and divisor to get the remainder instantly with full step-by-step working. Supports integers and decimals. Essential for number theory, computer science, and GCSE maths.
Modulo Reference Table
Common modulo results for quick reference:
| Expression | Division | Quotient | Remainder (mod) |
|---|---|---|---|
| 10 mod 3 | 10 ÷ 3 | 3 | 1 |
| 15 mod 4 | 15 ÷ 4 | 3 | 3 |
| 20 mod 5 | 20 ÷ 5 | 4 | 0 |
| 17 mod 7 | 17 ÷ 7 | 2 | 3 |
| 100 mod 12 | 100 ÷ 12 | 8 | 4 |
| 255 mod 16 | 255 ÷ 16 | 15 | 15 |
| 7 mod 2 | 7 ÷ 2 | 3 | 1 |
| 8 mod 2 | 8 ÷ 2 | 4 | 0 |
What Is the Modulo Operation?
The modulo operation (written a mod n or a % n) returns the remainder left over when integer a is divided by integer n. It answers the question: “after dividing as many whole times as possible, what is left over?”
For example: 17 mod 5 = 2, because 17 ÷ 5 = 3 remainder 2. Or equivalently, 5 × 3 = 15 and 17 − 15 = 2.
The word “modulo” comes from Latin meaning “with modulus”, introduced by the mathematician Carl Friedrich Gauss in his foundational 1801 work Disquisitiones Arithmeticae. Today it is one of the most used operations in computer science and number theory.
where floor() rounds down to the nearest integer. The result is always in the range [0, n−1].
How to Calculate Modulo Step by Step
- Identify dividend and divisor: In
a mod n, a is the dividend and n is the divisor (modulus). - Divide: Compute a ÷ n and round down to find the quotient q = floor(a ÷ n).
- Multiply: Compute q × n.
- Subtract: Remainder = a − (q × n).
Example 1: 23 mod 7
Step 1: 23 ÷ 7 = 3.285… → q = 3
Step 2: 3 × 7 = 21
Step 3: 23 − 21 = 2
Example 2: 100 mod 12
Step 1: 100 ÷ 12 = 8.333… → q = 8
Step 2: 8 × 12 = 96
Step 3: 100 − 96 = 4
Modular Arithmetic — The Clock System
Modular arithmetic is a system where numbers “wrap around” after reaching the modulus. The most familiar example is a 12-hour clock: after 12 o’clock, the next hour is 1 (not 13). This is mod 12 arithmetic.
- 15:00 on a 12-hour clock: 15 mod 12 = 3 (so 3 pm)
- Days of the week: 10 days after Wednesday (day 3 if Sunday = 0): (3 + 10) mod 7 = 13 mod 7 = 6 = Saturday
- Minute hand: 75 minutes = 75 mod 60 = 15 minutes past the hour
The notation a ≡ b (mod n) means a and b leave the same remainder when divided by n, or that (a − b) is divisible by n. This is called congruence and is studied at A-Level Further Maths and university number theory.
Modulo in Computer Science and Programming
The modulo operation is one of the most frequently used operations in programming. Here are key applications:
- Odd/Even detection: If n mod 2 = 0, the number is even; if n mod 2 = 1, it is odd. Used in virtually every programming language.
- Array wrapping / circular buffers: To cycle through an array of size n, use index mod n. This prevents out-of-bounds errors.
- Hash tables: Hash functions use mod to map keys to array positions: hash(key) mod tableSize.
- Random number generation: Linear congruential generators use modular arithmetic to produce pseudo-random sequences.
- Cryptography: RSA public-key encryption relies heavily on modular exponentiation: c = m³ mod n. AES, Diffie-Hellman, and elliptic curve cryptography all use modular arithmetic.
Modulo in Python, JavaScript, and Other Languages
| Language | Operator | 17 mod 5 | -7 mod 3 | Notes |
|---|---|---|---|---|
| Python | % | 2 | 2 | Always non-negative (mathematical definition) |
| JavaScript | % | 2 | -1 | Sign follows dividend (truncated division) |
| C / C++ | % | 2 | -1 | Sign follows dividend |
| Java | % | 2 | -1 | Sign follows dividend |
| Excel | MOD() | 2 | 2 | Always non-negative like Python |
| Maths notation | mod | 2 | 2 | Always in range [0, n−1] |
Divisibility Rules Using Modulo
Divisibility can be expressed using the modulo operation. A number a is divisible by n if and only if a mod n = 0.
- Divisible by 2: a mod 2 = 0 (even numbers)
- Divisible by 3: Sum of digits mod 3 = 0
- Divisible by 5: a mod 5 = 0 (ends in 0 or 5)
- Divisible by 9: Sum of digits mod 9 = 0
- Divisible by 10: a mod 10 = 0 (ends in 0)
The Luhn Algorithm — Modulo 10 in Real Life
Every credit card number in the UK and worldwide is validated using the Luhn algorithm, which works with modulo 10. When you type your card number online:
- Starting from the right, double every second digit.
- If the doubled result is ≥ 10, subtract 9.
- Sum all the digits.
- If the total mod 10 = 0, the number is valid.
This simple check catches most transcription errors instantly, without needing to contact the bank. It is built into every e-commerce website that accepts card payments in the UK.
ISBN Check Digit — Modulo 11
The older ISBN-10 system (before 2007) used modulo 11 for its check digit. ISBN-13 (the current standard) uses modulo 10. The check digit ensures that any single error in typing an ISBN changes the final check and reveals the mistake. The UK publishing industry relies on this system for all book distribution.
Modulo in GCSE and A-Level Maths
At GCSE level, modulo arithmetic appears in the context of remainder problems, divisibility, and sometimes codes or ciphers. The AQA, Edexcel, and OCR syllabi include problems such as:
- “Find the remainder when 247 is divided by 8.” (247 mod 8 = 7)
- “What is the units digit of 7¹⁰&sup0?” (requires finding the pattern of powers mod 10)
- “A shop sells eggs in boxes of 6. If there are 128 eggs, how many are left over?” (128 mod 6 = 2)
At A-Level Further Maths and university, modular arithmetic is studied formally with congruences, Euler’s theorem, and the Chinese Remainder Theorem.
Frequently Asked Questions
What is the modulo operation?
Modulo (mod) finds the remainder after integer division. For example, 17 mod 5 = 2 because 17 = 5 × 3 + 2. The result is always between 0 and the divisor minus 1 in standard mathematical usage.
What is the difference between mod and remainder?
For positive numbers they are identical. For negative numbers, mathematical modulo always gives a non-negative result, while some programming languages return a negative result. Python follows the mathematical definition; JavaScript and C do not.
How do I calculate modulo by hand?
Divide a by n, round down to get the quotient q, then: remainder = a − (q × n). Example: 23 mod 7 → floor(23/7)=3 → 23−(3×7)=23−21=2.
What is modular arithmetic?
A number system where values wrap around after reaching the modulus, like a clock. In mod 12, 14 ≡ 2. It is foundational in cryptography, computer science, and number theory.
What is a mod 0?
Undefined. Division by zero is not defined in mathematics, so modulo by zero is also undefined. Calculators and programming languages will return an error.
How is modulo used in programming?
Common uses include: odd/even detection (n%2), array index wrapping (i%length), hash tables, cyclic schedules, and cryptographic algorithms like RSA.
What does a ≡ b (mod n) mean?
It means a and b have the same remainder when divided by n, or that (a−b) is divisible by n. Read as “a is congruent to b modulo n”. For example, 17 ≡ 2 (mod 5).