Modulus Calculator
This modulus calculator finds a mod n, the remainder left after dividing a by n. 17 mod 5 = 2, because 17 = 3 × 5 + 2.
Sources: Wikipedia: Modulo Updated
Calculate the remainder when dividing two numbers
The modulo formula
a mod n = a − n × ⌊a ÷ n⌋
The brackets ⌊ ⌋ mean round down to the whole number below. For 17 mod 5: 17 ÷ 5 = 3.4, which rounds down to 3, and 17 − 5 × 3 = 2.
The calculator works it out as ((a % n) + n) % n, which gives the same result. For a positive n the result is at least 0 and less than n.
How to calculate 17 mod 5
- Find how many whole times 5 goes into 17: 3 times, which makes 15.
- Subtract: 17 − 15 = 2.
- The remainder is the answer: 17 mod 5 = 2.
This is the remainder from long division, without the quotient. When the remainder is 0, n is a factor of a, which the factor calculator lists for any whole number.
Modulo with negative numbers
For −7 mod 3, rounding down −7 ÷ 3 = −2.33… gives −3, and −7 − 3 × (−3) = 2. The calculator returns 2.
Programming languages disagree here. In JavaScript, C and Java, −7 % 3 gives −1, because their % rounds the quotient toward zero and keeps the sign of a. Python's % rounds down and gives 2. Wikipedia's modulo article compares the conventions.
| a | n | a mod n (this calculator) | a % n in JavaScript |
|---|---|---|---|
| 17 | 5 | 2 | 2 |
| −7 | 3 | 2 | −1 |
| 7 | −3 | −2 | 1 |
| −7 | −3 | −1 | −1 |
With a negative divisor, the calculator's result takes the sign of the divisor. A divisor of 0 is rejected, since division by zero is undefined.
Where the modulus is used
Clock arithmetic is mod 24: 15 hours after 14:00 is (14 + 15) mod 24 = 5, so 05:00. A number is even when n mod 2 = 0, and programs use i mod length to wrap around a list.
Repeated mod is also the core of Euclid's algorithm for the greatest common factor: gcd(48, 18) = gcd(18, 12) = gcd(12, 6) = 6, as in the GCF calculator.
Questions about the modulus
What does mod mean?
Mod is short for modulo: a mod n is the remainder when a is divided by n. 23 mod 4 = 3, because 4 goes into 23 five times (20) with 3 left over.
What is 0 mod n, and what is n mod n?
Both are 0. Zero divided by any non-zero n leaves nothing over, and n goes into itself exactly once.
Can I use decimals?
Yes. The same rule applies: 7.5 mod 2 = 1.5, because 2 goes into 7.5 three times (6) and 1.5 is left.
Sources
- Wikipedia: Modulo — floored and truncated division, and which sign the remainder takes in each (checked October 16, 2026)