By Tim King · Updated
Modulo Calculator
Find a mod n and the Remainder, Including Negative Numbers
OneTask is free, with no sign-up, and built by one person.
If this tool saved you time, a coffee helps keep new ones coming.
How the Modulo Calculator works
This modulo calculator finds a mod n, the remainder after dividing a by n, for whole numbers of any length. Negative numbers are where languages disagree, so it shows the floored result used by Python and maths, the truncated % used by JavaScript, C and Java, and the always-positive Euclidean remainder, plus whether n divides a exactly.
Modular arithmetic is clock arithmetic: 15 o'clock is 3 o'clock because 15 mod 12 = 3. It powers hashing, check digits, cryptography and anything that repeats in cycles, such as weekdays. For two positive numbers every convention agrees. The split comes when a or n is negative, because the quotient can be rounded down or toward zero, and that choice decides the sign of the remainder.
How the modulo calculator works
The formula is a mod n = a − n × q, where q is the quotient. Floored modulo uses q = floor(a / n), so the result takes the sign of n. Truncated % uses q rounded toward zero, so the result takes the sign of a. The Euclidean remainder is always between 0 and |n| − 1. Arithmetic uses big integers, so numbers with hundreds of digits stay exact.
First example. 17 mod 5 = 2, because 17 = 5 × 3 + 2. All three conventions agree.
Second example. -17 mod 5 is 3 when floored, since -17 = 5 × -4 + 3, but -17 % 5 in JavaScript or C is -2, since -17 = 5 × -3 − 2.
How many days after Monday is 100 days later? 100 mod 7 = 2, so it is two days on: a Wednesday.
How the three remainder conventions differ with negative numbers
| a | n | Floored mod (Python, Excel MOD) | Truncated % (JS, C, Java) | Euclidean |
|---|---|---|---|---|
| 17 | 5 | 2 | 2 | 2 |
| -17 | 5 | 3 | -2 | 3 |
| 17 | -5 | -3 | 2 | 2 |
| -17 | -5 | -2 | -2 | 3 |
| 10 | 3 | 1 | 1 | 1 |
| -10 | 3 | 2 | -1 | 2 |
| 7 | 7 | 0 | 0 | 0 |
| 0 | 4 | 0 | 0 | 0 |
| 3 | 8 | 3 | 3 | 3 |
| -3 | 8 | 5 | -3 | 5 |
| 100 | 7 | 2 | 2 | 2 |
| -100 | 7 | 5 | -2 | 5 |
| 25 | 24 | 1 | 1 | 1 |
| -1 | 24 | 23 | -1 | 23 |
| 365 | 7 | 1 | 1 | 1 |
| 1000 | 60 | 40 | 40 | 40 |
| -7 | 2 | 1 | -1 | 1 |
| 13 | 12 | 1 | 1 | 1 |
| 59 | 60 | 59 | 59 | 59 |
| -59 | 60 | 1 | -59 | 1 |
Tips and pitfalls
- Check your language. Python's % is floored; JavaScript, C, C++, Java and Go use truncated.
- Want a positive index? Use ((a % n) + n) % n in truncated languages to get the floored result.
- Mod 0 is undefined. Dividing by zero has no remainder, so the calculator asks for a non-zero n.
- Use text for big numbers. Spreadsheets lose precision past 15 digits; this tool does not.
FAQ
What does mod mean in maths?
a mod n is the remainder left when a is divided by n. So 23 mod 6 = 5, because 6 goes into 23 three times with 5 left over. When the remainder is 0, n divides a exactly, which is how divisibility and even or odd checks are written.
How do you calculate modulo with negative numbers?
It depends on the rule. Floored modulo, used in maths and Python, gives -7 mod 3 = 2. Truncated remainder, used by % in JavaScript, C and Java, gives -7 % 3 = -1. Both satisfy a = n × q + r; they just choose a different quotient.
Is modulo the same as remainder?
For positive numbers, yes. With negatives they can differ in sign: the remainder from truncated division follows the dividend, while the floored modulo follows the divisor. Many programming languages call their % operator modulo even though it is technically a remainder.
What is 10 mod 3?
10 mod 3 = 1, because 3 × 3 = 9 and 10 − 9 = 1. The floored quotient is 3. In every convention the answer is the same here because both numbers are positive, so the result is always 1 whichever language you use.
What is modulo used for?
It finds the day of the week, wraps array indexes, checks whether a number is even, validates barcodes and card numbers with check digits, and sits at the heart of RSA and other cryptography. Any value that cycles, such as hours or angles, uses it.
See also: all Arithmetic tools, Number Theory, Algebra and Geometry, Statistics, Trigonometry and Calculus.
Related tools
GCF Calculator
Greatest common factor of two or more numbers, with every step.
Prime Number Checker
Check if a number is prime, or list the primes in a range.
Factor Calculator
All the factors, factor pairs and prime factorisation of a number.
Scientific Calculator
Trig, logs, powers, factorials and memory, in one expression.
Long Division Calculator
Long division with every step shown, remainders or decimals.