Find the remainder of a division.
Enter a dividend and a divisor to see the modulo remainder, the quotient, and the full a = n times q plus r identity, with the programming style remainder shown side by side.
Your numbers
What this means
Nearby dividends
| Dividend a | Quotient q | a mod n | a % n |
|---|
How the modulo works
What the modulo operation does
The modulo operation returns the remainder left over after you divide one number by another. Written a mod n, it takes the dividend a, removes as many whole copies of the divisor n as will fit, and reports whatever is left. If a is 17 and n is 5, then 5 fits into 17 three times with 2 left over, so 17 mod 5 = 2. The quotient q is the count of whole copies, here floor(17 / 5) = 3, and together they satisfy the identity a = n times q + r.
Because the remainder is always smaller in size than the divisor, a floored modulo result sits between 0 and n. That bounded behavior is exactly why modulo powers clock arithmetic, hashing, cycling through a fixed set of buckets, checking whether one number divides another, and wrapping a list index back to the front.
Floored modulo versus the programming remainder
There are two common ways to define the remainder, and they only disagree when negative numbers are involved. The mathematical, floored version uses q = floor(a / n), so the remainder r = a - n times q always carries the same sign as the divisor n. The truncated version, written a % n in most programming languages such as C, Java, and JavaScript, rounds the quotient toward zero, so its remainder carries the same sign as the dividend a.
For example, -7 mod 3 is 2 under the floored definition, because -7 = 3 times -3 + 2. But -7 % 3 is -1 in many languages, because -7 = 3 times -2 - 1. The two answers always differ by exactly one copy of n whenever a and n have opposite signs. This calculator shows both values so you can pick the one that matches your language or your math, and it lists nearby dividends so you can watch the remainder cycle.
Common questions
What is the modulo of two numbers?
The modulo is the remainder after dividing the first number by the second. For a mod n you remove every whole copy of n from a, and whatever is left over is the result. For example 17 mod 5 = 2 because 5 goes into 17 three times, leaving 2.
How do you calculate a mod n by hand?
Divide a by n and take the whole-number part as the quotient q, which is floor(a / n). Multiply q by n and subtract that from a. The result r = a - n times q is the modulo remainder, and it always satisfies a = n times q + r.
Why is the modulo of a negative number sometimes positive?
Under the mathematical floored definition the remainder always takes the sign of the divisor, so a negative dividend with a positive divisor gives a positive remainder. For instance -7 mod 3 = 2. Many programming languages instead use a % n, which keeps the sign of the dividend and would return -1 here.
What happens if the divisor is zero?
Modulo by zero is undefined, just like dividing by zero, because there is no meaningful number of copies to remove. The calculator flags this and asks you to enter a non-zero divisor.
Can modulo be used with decimals?
Yes. The same rule applies: r = a - n times floor(a / n). For example 5.5 mod 2 = 1.5. Floating point rounding can make results look slightly off, so this tool rounds tiny errors back to a clean value.
What is the difference between the quotient and the remainder?
The quotient is how many whole times the divisor fits into the dividend, and the remainder is what is left after those whole copies are taken out. Together they rebuild the original number through a = n times q + r.
The mathematical modulo shown as the headline uses floored division, so the remainder always carries the same sign as the divisor and stays between 0 and n. The a % n column uses truncated division, the style most programming languages follow, so its sign matches the dividend.