Find a mod n — the remainder and quotient of a division.
Calculated locally in your browser.
How do you calculate a mod n?
a mod n = a − n × floor(a ÷ n). With this floored definition the result takes the divisor's sign, while languages like C, Java and JavaScript use a truncated remainder following the dividend. For 17 mod 5, floor(17 ÷ 5) = 3, so 17 − 5 × 3 = 2. The two agree for positive numbers and differ only when a is negative.
Understanding your result
For positive a and n the floored and truncated results match. They differ only when a is negative: the floored modulo keeps the result in the range 0 to n − 1 (handy for cyclic values), while the truncated remainder mirrors the dividend's sign. This calculator shows both so there is no ambiguity.
Formula and method
a mod n = a − n × floor(a ÷ n). With the floored definition the result has the same sign as the divisor; programming languages such as C, Java and JavaScript instead use a truncated remainder whose sign follows the dividend.
Worked example
17 mod 5: floor(17 ÷ 5) = 3, so 17 − 5 × 3 = 2. For −17 mod 5 the floored result is 3, while −17 % 5 in JavaScript is −2.
How to use this tool
- Enter the dividend (a).
- Enter the divisor (n) — it cannot be zero.
- Read a mod n, the quotient and the divisibility check.
Common mistakes to avoid
- Dividing by zero — the modulo is undefined.
- Assuming the result of a negative dividend is always positive.
- Confusing the remainder with the quotient.
About the Modulo Calculator
The Modulo Calculator returns the remainder after dividing a by n, written a mod n. It also shows the quotient and, for negative numbers, both the mathematical (floored) and programming (truncated) results.
Who should use this tool
Students, programmers and anyone working with remainders, clock arithmetic or cycles.
Benefits
- Clear a mod n result with the quotient.
- Handles negative numbers, showing floored and truncated results.
- Tells you whether a divides evenly into n.
- Private — calculated entirely in your browser.
Practical use cases
- Checking divisibility or whether a number is even or odd.
- Wrapping a value into a range (clock or angle arithmetic).
- Verifying a remainder when learning long division.
Frequently asked questions
What is the modulo operation?
It returns the remainder after dividing one number by another. For example, 17 mod 5 is 2 because 17 = 3 × 5 + 2.
Why do negative numbers give two answers?
There are two common conventions. The mathematical (floored) modulo is non-negative for a positive divisor; the truncated remainder used by many programming languages follows the sign of the dividend.
Can I use decimals?
Yes. The calculator accepts decimal values for both the dividend and divisor and applies the same formula.