Modulo Calculator
Calculate the modulo (remainder) of a division operation.
Enter Values
Expression
Remainder (Modulo)
2
17 mod 5 = 2
Division Details
Verification
dividend = quotient * divisor + remainder
17 = 3 * 5 + 2
17 = 17 (correct)
Modulo Operation
Definition
The modulo operation finds the remainder after division.
Properties
0 ≤ a mod b < |b| (for mathematical modulo)
(a + b) mod n = ((a mod n) + (b mod n)) mod n
(a * b) mod n = ((a mod n) * (b mod n)) mod n
What is the Modulo Operation?
The modulo operation (also called modulus or mod) finds the remainder after dividing one number by another. It's a fundamental operation in mathematics and computer science, used in everything from cryptography to everyday calculations like determining what day of the week it will be.
Definition:
- a mod n = the remainder when a is divided by n
- Notation: a mod n, a % n (programming), or a (mod n)
- Result is always between 0 and n-1 (for positive n)
Simple Examples:
| Operation | Division | Result | Explanation |
|---|---|---|---|
| 17 mod 5 | 17 = 5×3 + 2 | 2 | Remainder after dividing 17 by 5 |
| 24 mod 6 | 24 = 6×4 + 0 | 0 | 24 is divisible by 6 |
| 7 mod 10 | 7 = 10×0 + 7 | 7 | 7 < 10, so remainder is 7 |
| 100 mod 7 | 100 = 7×14 + 2 | 2 | 14 sevens fit, 2 left over |
Modulo Formula and Definition
The modulo operation can be defined mathematically:
Modulo Definition
Where:
- a= Dividend (number being divided)
- n= Divisor (modulus)
- ⌊x⌋= Floor function - greatest integer ≤ x
- q= Quotient (integer result of division)
- r= Remainder (mod result)
Properties of Modular Arithmetic
Modular arithmetic follows specific rules that make calculations easier:
Modular Arithmetic Properties
Where:
- a, b= Any integers
- n= The modulus
- mod= Modulo operation
Negative Numbers and Modulo
Handling negative numbers in modulo varies by definition:
| Definition | -7 mod 3 | Used In |
|---|---|---|
| Truncated Division | -1 | C, C++, Java, JavaScript |
| Floored Division | 2 | Python, Ruby, Mathematics |
| Euclidean | 2 | Mathematical definition |
To always get a positive result:
((a mod n) + n) mod n works in any language
Example: -7 mod 3
- Truncated: -7 = 3 × (-2) + (-1), so result is -1
- Floored: -7 = 3 × (-3) + 2, so result is 2
How to Use This Calculator
Our modulo calculator handles various operations:
- Enter Dividend: The number being divided (a)
- Enter Divisor: The modulus (n)
- Click Calculate: Get the remainder
- View Results:
- Remainder (mod result)
- Quotient (integer division)
- Full equation: a = n × q + r
- Both truncated and floored results
Additional Features:
- Modular arithmetic calculator
- Modular exponentiation (a^b mod n)
- Modular inverse finder
- Congruence checker
Input Types:
- Positive integers: 17 mod 5
- Negative integers: -7 mod 3
- Large numbers: 123456789 mod 97
Applications of Modulo
Modulo is essential in many practical applications:
Time and Calendars:
- Clock arithmetic: (hour + x) mod 12 or mod 24
- Day of week: (today + days) mod 7
- Leap years: year mod 4 = 0 (simplified)
Computer Science:
- Hash functions: index = hash mod table_size
- Circular buffers: pos = (pos + 1) mod size
- Random numbers: Many generators use modulo
- Array indexing: Wrap-around behavior
Cryptography:
- RSA encryption: c = m^e mod n
- Diffie-Hellman: Key exchange
- Hash functions: MD5, SHA use modular arithmetic
- Checksums: ISBN, credit card validation
Everyday Uses:
- Even/odd check: n mod 2 (0 = even, 1 = odd)
- Digit extraction: n mod 10 gets last digit
- Divisibility: a mod b = 0 means b divides a
- Cycling through options: next = (current + 1) mod total
Modular Multiplicative Inverse
The modular inverse of a (mod n) is a number b such that (a × b) mod n = 1:
Modular Inverse
Where:
- a⁻¹= Modular inverse of a
- ≡= Congruent (equal under mod)
- GCD= Greatest Common Divisor
Worked Examples
Basic Modulo Calculation
Problem:
Calculate 47 mod 8
Solution Steps:
- 1Divide 47 by 8: 47 ÷ 8 = 5.875
- 2Integer part (quotient) = 5
- 3Quotient × divisor = 5 × 8 = 40
- 4Remainder = 47 - 40 = 7
- 5Verify: 8 × 5 + 7 = 40 + 7 = 47 ✓
Result:
47 mod 8 = 7
Clock Arithmetic
Problem:
It's 10 AM. What time will it be in 27 hours?
Solution Steps:
- 1Current hour: 10
- 2Add hours: 10 + 27 = 37
- 3Apply mod 24: 37 mod 24
- 437 = 24 × 1 + 13
- 5Result: 13 (1 PM on a 24-hour clock)
- 6Or: (37 mod 12) = 1 (1 o'clock on 12-hour)
Result:
1 PM (13:00)
Day of Week Calculation
Problem:
Today is Tuesday (day 2). What day will it be in 100 days?
Solution Steps:
- 1Number the days: Sun=0, Mon=1, Tue=2, ..., Sat=6
- 2Today = 2 (Tuesday)
- 3Add days: 2 + 100 = 102
- 4Apply mod 7: 102 mod 7
- 5102 = 7 × 14 + 4
- 6Result: 4 = Thursday
Result:
Thursday
Tips & Best Practices
- ✓a mod n is always between 0 and n-1 (for positive n in most definitions)
- ✓If a < n, then a mod n = a (nothing to divide)
- ✓a mod n = 0 means n divides a evenly (a is divisible by n)
- ✓n mod 2 is 0 for even numbers, 1 for odd numbers
- ✓n mod 10 gives the last digit of n
- ✓For negative numbers: ((a mod n) + n) mod n always gives positive result
- ✓Modular arithmetic preserves operations: (a + b) mod n = ((a mod n) + (b mod n)) mod n
Frequently Asked Questions
Sources & References
Last updated: 2026-01-22