Modulo Calculator

Compute remainders, modular arithmetic operations, congruences, and clock math.

What Is Modulo?

The modulo operation (written as a mod m or a % m) returns the remainder when integer a is divided by integer m (the modulus). It is based on the division algorithm: for any integers a and m (m>0), there exist unique integers q (quotient) and r (remainder) such that a = q × m + r where 0 ≤ r < m.

Modular arithmetic is sometimes called clock arithmetic because of its cyclic nature — just like hours on a clock wrap around from 12 back to 1. It underpins modern cryptography (RSA, Diffie-Hellman), hash functions, checksums, cyclic data structures, and calendar calculations (what day of the week is a given date?).

Floor vs Truncated modulo: For positive numbers both give the same result. For negative numbers they differ. Python uses floor division: −7 mod 3 = 2 (always non-negative). C, Java, and JavaScript use truncated division: −7 % 3 = −1 (sign matches the dividend). Mathematically the floor version is more consistent with number theory.

Modulo vs Remainder — Negative Number Comparison

ExpressionFloor (Python)Truncated (C/JS)
17 mod 522
-7 mod 32-1
7 mod -3-21
-7 mod -3-1-1

Frequently Asked Questions

Modulo returns the remainder after dividing one number by another. For 17 mod 5: 17 = 3×5 + 2, so the result is 2. It is the foundation of modular arithmetic and used widely in programming.
For positive numbers, they are identical. For negative numbers, floor modulo (Python) always returns a non-negative result, while truncated remainder (C, Java, JavaScript %) can return a negative result. The sign behavior differs when a or m is negative.
Modular arithmetic is a number system where numbers wrap around upon reaching a given value (the modulus). Think of a clock: after 12, we go back to 1. Two numbers are "congruent modulo m" if they give the same remainder when divided by m.
The modular inverse of a modulo m is a number x such that (a × x) ≡ 1 (mod m). It exists only when gcd(a, m) = 1. It is computed using the extended Euclidean algorithm and is essential in RSA decryption.
RSA encryption relies on modular exponentiation: ciphertext = messageᵉ mod n. The security comes from the difficulty of computing discrete logarithms and integer factorization. Diffie-Hellman key exchange and elliptic curve cryptography also depend on modular arithmetic.
Clock arithmetic is arithmetic modulo 12 (or 24). If it's 10 o'clock and you add 5 hours: (10 + 5) mod 12 = 3. The same principle applies in computing for cyclic buffers, hash tables, and scheduling algorithms.
This notation means a and b are congruent modulo m: they have the same remainder when divided by m, or equivalently, m divides (a − b). Example: 17 ≡ 5 (mod 6) because both give remainder 5 when divided by 6 (17 − 5 = 12 = 6×2).
0 mod m = 0 for any non-zero m, since 0 = 0 × m + 0. The remainder is always 0. Division by zero (a mod 0) is undefined.

Related Calculators