Modulo Calculator

Calculate the modulo (remainder) of any division. Supports negative numbers in both math and programming conventions, clock arithmetic, modular exponentiation, and congruence checks.

Remainder (a mod b)
Quotient
Division Equation
Extended More scenarios, charts & detailed breakdown
Remainder
Quotient
Equation
Professional Full parameters & maximum detail
a mod b (mathematical)
a % b (programming/truncation)
aᶜ mod b (modular exponentiation)
a⁻¹ mod b (modular inverse)
Is a ≡ k (mod b)?
Application Note

How to Use This Calculator

Enter the dividend (a) and the divisor (b). The result shows the remainder, quotient, and full division equation. Use the Clock Arithmetic tab to find what time it will be after N hours. Use the Batch tab to compute mod for 5 numbers at once. The Professional tab adds negative number handling, modular exponentiation, and modular inverse.

Formula

Math mod: a mod b = a − b × ⌊a/b⌋ (result always ≥ 0) • Programming: a % b = a − b × trunc(a/b)

Example

17 mod 5 = 2 (17 = 5×3 + 2) • −7 mod 3 = 2 (math) vs −1 (programming) • 2³ mod 5 = 8 mod 5 = 3

Frequently Asked Questions

  • The modulo operation returns the remainder after dividing one number by another. Written a mod b or a % b, the result r satisfies: a = b × q + r, where q is the integer quotient and 0 ≤ r < b. For example, 17 mod 5 = 2 because 17 = 5 × 3 + 2. Similarly, 20 mod 4 = 0 (divides evenly), and 7 mod 10 = 7 (7 is less than 10, so nothing divides). Modulo is used in cyclic calculations, hash tables, random number generation, and cryptography.
  • For positive numbers, mod and remainder are identical. They differ only for negative numbers. In mathematics, the result of a mod b is always non-negative (0 to b−1): −7 mod 3 = 2, because −7 = 3 × (−3) + 2. In most programming languages (Python %, Java %, C %), the result takes the sign of the dividend: −7 % 3 = −1, because −7 = 3 × (−2) + (−1). This calculator offers both conventions. Use the math convention for cryptography and number theory; use the programming convention when matching code behavior.
  • Clock arithmetic is a practical application of modular arithmetic where numbers "wrap around" after reaching a maximum. A 12-hour clock uses modulo 12. If the current time is 10:00 and you add 27 hours: (10 + 27) mod 12 = 37 mod 12 = 1, so the new time is 1:00 AM. A 24-hour clock uses modulo 24. Day-of-week calculations use modulo 7. If today is Wednesday (day 3 in a 0=Sunday convention) and you add 10 days: (3 + 10) mod 7 = 13 mod 7 = 6 = Saturday.
  • Modular exponentiation computes (a^c) mod b efficiently — without ever computing the potentially enormous number a^c directly. The repeated-squaring algorithm computes this in O(log c) multiplications. Example: 2^¹⁰ mod 7. 2^1=2, 2^2=4, 2^4=16≡2, 2^8≡4, 2^10=2^8×2^2≡4×4=16≡2 (mod 7). Modular exponentiation is the foundation of RSA encryption, Diffie-Hellman key exchange, and digital signatures — it is fast to compute but hard to reverse (discrete logarithm problem).
  • The modular inverse of a modulo m is a number x such that (a × x) ≡ 1 (mod m). It is the modular analogue of dividing by a. Example: 3 × 5 = 15 ≡ 1 (mod 7), so 5 is the modular inverse of 3 modulo 7. The inverse exists if and only if gcd(a, m) = 1 (a and m are coprime). It is found using the Extended Euclidean Algorithm. Modular inverses are essential in RSA decryption, solving linear congruences, and the Chinese Remainder Theorem.

Related Calculators