Modulo Calculator (a mod n)
Enter a number and the modulus.
Your numbers
Your results
Modulo Calculator (a mod n) by TheCalcTools
How the Modulo Calculator (a mod n) works
The modulo is what is left after division. For positive numbers both conventions agree. With a negative number they differ: the floored version (used in mathematics and Python) gives a result with the sign of the modulus; the truncated version (C, Java, JavaScript %) gives the sign of the dividend.
Clock arithmetic is mod 12 (or 24): 15:00 is 3 o’clock because 15 mod 12 = 3.
The formula
Worked example
Using the default values shown in the calculator:
| Number (a) | -17 |
|---|---|
| Modulus (n) | 5 |
- −17 mod 5 = 3.0000 (floored); −17 % 5 = -2.0000 (truncated).
Result:
| a mod n (floored, always the sign of n) | 3.0000 |
|---|---|
| Remainder a % n (truncated, sign of a) | -2.0000 |
| Floored quotient | -4 |
| Truncated quotient | -3 |
| Congruence | -17 ≡ 3 (mod 5) |
Frequently asked questions
What is −17 mod 5?
3 with the floored (mathematical) definition, and −2 with the truncated definition used by % in C and JavaScript.
Sources and further reading
Related calculators
More in Math · All calculators
This calculator gives estimates for information only. Check important results independently before you rely on them. See our disclaimer.
