Modulo Calculator
Modulo Calculator – Understand Modular Arithmetic
The modulo operation finds the remainder after dividing one number by another. Our free modulo calculator shows the quotient (integer part), the remainder, and the exact division result for any two numbers you enter. It also explains the important difference between remainder and modulo for negative numbers.
What Is the Modulo Operation?
If you divide A by B, you get a quotient Q and a remainder R such that: A = B × Q + R. The modulo operation, written as A mod B, gives you R. For example:
- 17 mod 5 = 2 (because 17 = 5 × 3 + 2)
- 20 mod 4 = 0 (because 20 = 4 × 5 + 0 — evenly divisible)
- 7 mod 3 = 1 (because 7 = 3 × 2 + 1)
Modulo vs Remainder: The Negative Number Difference
For positive numbers, modulo and remainder give the same result. But for negative numbers, different programming languages and mathematical systems handle them differently:
- Truncated division (C, Java, JavaScript): The remainder has the same sign as the dividend. −7 % 3 = −1 (because −7 = 3 × (−2) + (−1)).
- Floored division (Python, mathematical modulo): The remainder is always non-negative when the divisor is positive. −7 mod 3 = 2 (because −7 = 3 × (−3) + 2).
This calculator shows both values when negative numbers are involved, along with a clear explanation.
Practical Applications of Modulo
- Programming: Checking if a number is even or odd (n % 2 === 0 means even).
- Cyclic patterns: Clock arithmetic (hours wrap at 12 or 24 using modulo).
- Hashing: Distributing data into buckets (index = hash % bucketCount).
- Cryptography: RSA, Diffie-Hellman, and elliptic curve systems rely on modular exponentiation.
- Calendars: Determining the day of the week for any date.
- Checksums: ISBN, credit card, and barcode validation use modulo arithmetic.
Modular Arithmetic in Mathematics
Modular arithmetic, formalized by Carl Friedrich Gauss in 1801, treats numbers that differ by a multiple of a modulus as equivalent. This "clock arithmetic" underpins much of number theory, abstract algebra, and modern cryptography. Two numbers a and b are said to be congruent modulo n (written a ≡ b mod n) if they have the same remainder when divided by n.
