
How to Use the Modulo Calculator

- Enter the dividend a. Whole numbers of any size and decimals work.
- Enter the divisor n (the modulus).
- Read a mod n, then the quotient and each remainder convention with the steps.
Enter the dividend a and the divisor n, also called the modulus. The modulo calculator shows a mod n as the main answer, together with the whole-number quotient and the remainder under three common conventions.
Try the examples to see how negative numbers, a big integer, a decimal and clock hours behave. Each result shows the congruence and a short list of steps, ending with a check of the answer.
Use Copy to paste the result into notes or code. The tool works as a modulus calculator for whole numbers of any size, and it also accepts decimals and fractions such as 7.5 or 1/3.
The Modulo Formula
The modulo operation finds what is left over after dividing a by n as many whole times as possible. Every result satisfies a equals n times q plus r, with quotient q and remainder r.
Floored: q = ⌊a ÷ n⌋, r = a − n × q (r has the sign of n)
Truncated: q = trunc(a ÷ n), r = a − n × q (r has the sign of a)
Euclidean: 0 ≤ r < |n|
Worked example: 17 mod 5. Dividing 17 by 5 gives 3.4, and we round down to a quotient of 3. The remainder is 17 minus 5 times 3, so 17 mod 5 equals exactly 2.
To check, multiply back: 5 times 3 plus 2 gives 17. Floored division, truncated division and the Euclidean rule all agree here, because both numbers are positive. They only differ once a negative sign appears.
Modulo With Negative Numbers
With negative numbers, programming languages disagree because they round the quotient differently. For negative 17 mod 5, the exact quotient is negative 3.4, and the choice of rounding changes the remainder that finally comes out.
Floored division rounds down to negative 4, giving a remainder of 3, which takes the sign of the divisor. Truncated division rounds toward zero, giving negative 2. Python and Excel use floored; JavaScript uses truncated.
In mathematics, a mod n with a positive modulus means the non-negative result, which is the main answer shown here. The % operator in the ECMAScript language specification is truncated, so use ((a % n) + n) % n.
| Language or tool | Operator | −17 mod 5 | 17 mod −5 |
|---|---|---|---|
| Python | % | 3 | −3 |
| Excel, Google Sheets | MOD() | 3 | −3 |
| JavaScript, C, C++, Java, C# | % | −2 | 2 |
| Euclidean (number theory) | mod | 3 | 2 |
Congruence and Modular Arithmetic
Two numbers are congruent modulo n when they leave the same remainder after division by n. We write 17 is congruent to 2 mod 5, because both leave 2, and the calculator shows this line.
Modular arithmetic, formalized by Carl Friedrich Gauss, works with these remainders instead of full numbers. Sums and products can be reduced at every step, which keeps numbers small even in very long calculations by hand.
That idea is central to number theory and computer science. The MIT Mathematics for Computer Science course covers modular arithmetic alongside proofs and counting, and it is a good next step for the full theory.
Where Modulo Is Used
Clock arithmetic is the classic example. On a 24-hour clock, 1000 hours after midnight is 1000 mod 24, which is 16, so the clock time lands at 16:00, even though many whole days have passed.
A number is even when it mod 2 equals 0, otherwise odd. Check digits in ISBN codes and many ID numbers use mod 10 or mod 11 tests to catch typing errors before they spread.
In cryptography, RSA and similar systems do arithmetic mod very large numbers. In everyday programming, modulo cycles through array positions, alternates row colors and splits work into equal batches, all with one very short expression.
- Clock arithmetic: 1000 mod 24 = 16.
- Even and odd: a number is even when it mod 2 = 0.
- Check digits: ISBN and many ID numbers use mod 10 or mod 11.
- Cryptography: RSA works mod very large numbers.
- Programming: cycling through array positions and batches.
Quotient and Remainder Together
Division with remainder always produces two results: the whole number quotient q and the remainder r. The quotient answers how many times n fits into a, and the remainder answers how much is left over.
Many languages return both at once, such as divmod in Python, which uses floored division. The calculator shows both the floored quotient and the truncated quotient, so you can match whichever language you are using.
The check line in the steps confirms that n times q plus r gives back the original number. If that check fails in your own code, the quotient and remainder came from different rounding conventions.
Big Numbers and Decimals
Whole numbers are stored as JavaScript BigInt values, so there is no upper limit apart from the memory of your device. For example, 123456789012345678901234567890 mod 97 equals 52, computed exactly with no rounding at all.
Decimals and fractions are handled exactly as fractions rather than as floating point numbers. So 5.5 mod 2 equals 1.5, since 5.5 is 2 times 2 plus 1.5, and there are no tiny rounding errors.
Everything runs in your browser, and nothing is sent to a server. That keeps results instant, even for very long numbers, and means you can safely use the tool for homework, coding checks or puzzles.
Frequently asked questions
What does mod mean in math?
a mod n is the remainder when a is divided by n. For example, 17 mod 5 equals 2, because 17 is 5 times 3 plus 2. For a positive n, the result lies between 0 and n minus 1.
What is -17 mod 5?
In mathematics, Python and Excel it is 3. In JavaScript, C and Java the % operator gives negative 2, because those languages round the quotient toward zero instead of down.
How do I calculate mod by hand?
Divide a by n and round the result down to a whole number q. Then multiply n by q and subtract that from a. What remains is a mod n, which you can check by adding back.
Is modulo the same as remainder?
For positive numbers, yes. For negative numbers they can differ: the remainder from truncated division takes the sign of a, while the modulo from floored division takes the sign of n.
Can I use modulo with decimals?
Yes. 5.5 mod 2 equals 1.5, since 5.5 is 2 times 2 plus 1.5. The calculator handles decimals and fractions exactly, so there are no floating point rounding errors in the answer.
What is the difference between modulo and congruence?
Modulo is an operation that returns a remainder. Congruence is a relationship: two numbers are congruent mod n when they share the same remainder, such as 17 and 2 mod 5.