How this modulo calculator works
The modulo operation returns the remainder after one whole number is divided by another. Written a mod n, it answers the question: after taking out as many whole copies of n as possible from a, how much is left over? The leftover amount is the remainder, and the number of whole copies removed is the integer quotient q. Together they always satisfy the identity a = n × q + r.
For positive operands this is unambiguous. When the dividend a is negative, two different conventions disagree. The truncated form — used by the % operator in C, Java and JavaScript — rounds the quotient toward zero, so the remainder takes the sign of the dividend. The Euclidean (floored) form rounds the quotient down toward negative infinity, so the remainder is always non-negative. This calculator shows both, labelled clearly, so you can match whichever your language or formula expects.
% convention (−17 = 5 × −3 + −2). Both are "correct" — they just use different rounding rules for the quotient.Reference note: this tool works with integers. The divisor must be non-zero, because dividing by zero leaves no defined remainder. Internally the Euclidean result is computed as ((a % n) + |n|) % |n| so it stays in the range 0 to |n| − 1.
Frequently asked questions
- What is the modulo operation?
- The modulo operation, written a mod n, gives the remainder left over after dividing the dividend a by the divisor n. For example, 17 mod 5 is 2, because 17 divided by 5 is 3 with 2 left over. It satisfies a = n × q + r.
- How do I calculate a mod n?
- Divide a by n and take the whole-number quotient q, then compute the remainder r = a − n × q. With the Euclidean convention the remainder is always between 0 and n − 1. For 17 mod 5 the quotient is 3 and the remainder is 2.
- What is modulo of a negative number?
- It depends on the convention. The truncated form (C, Java, JavaScript) keeps the sign of the dividend, so −17 % 5 is −2. The Euclidean form is always non-negative, so −17 mod 5 is 3. This calculator shows both.
- What is the difference between mod and remainder?
- For positive numbers they are identical. They differ only for negative dividends: the % operator keeps the dividend's sign (truncated), while mathematical modulo is usually non-negative (Euclidean). Always check which convention a tool uses.
- What is 10 mod 3?
- 10 mod 3 is 1. Ten divided by three is three with one left over, since 3 × 3 = 9 and 10 − 9 = 1. The quotient is 3 and the remainder is 1, so 10 = 3 × 3 + 1.
- What is modulo used for?
- It tests divisibility (a mod n == 0), wraps values into a range like clock hours or array indices, extracts digits, and powers hashing, checksums and cryptography. Checking if a number is even is just n mod 2 == 0.