Modulo Calculator

Modulo Calculator

÷
Quotient (integer part)
Remainder (A mod B)
Exact Division (A ÷ B)

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.

Frequently Asked Questions

What does A mod B equal when A is smaller than B?
When A is smaller than B (and both are positive), the result is just A itself. For example, 3 mod 7 = 3 because 3 = 7 × 0 + 3.
What is A mod 1?
A mod 1 is always 0, because every integer is divisible by 1 with no remainder.
What is A mod A?
A mod A is always 0, because any number divided by itself has a remainder of 0.
Why do Python and JavaScript give different modulo results for negative numbers?
Python uses floored division (result sign follows divisor), so −7 % 3 = 2. JavaScript/C use truncated division (result sign follows dividend), so −7 % 3 = −1. Both are self-consistent systems; the difference matters when working across languages.
Can the modulo operation be applied to decimal numbers?
Yes. The modulo operation is defined for real numbers too. For example, 5.7 mod 2.3 ≈ 1.1 (because 5.7 = 2.3 × 2 + 1.1). This calculator supports decimal inputs.