What is the modulo operation?
The modulo operation, written a mod b, returns the remainder left over when the dividend a is divided by the modulus (divisor) b. It is everywhere in computing and mathematics: clock arithmetic, hashing, cycling through a list, checking divisibility, and cryptography all rely on it. This tool computes the remainder for positive numbers, negative numbers and decimals, and shows a full step-by-step proof.
How to use it
Enter the Dividend (a) and the Modulus / Divisor (b). Either value may be negative or a decimal — use the +/- button to flip a sign quickly. The divisor must not be zero, because dividing by zero is undefined. The result shows the remainder, the integer quotient, an optional floored-modulo value, and a written proof.
The formula explained
This calculator uses the truncated-division convention, the same rule the % operator follows in C, Java and JavaScript. First the quotient is truncated toward zero: q = trunc(a / b). Then the remainder is n = a - q*b. Because the quotient is truncated rather than floored, the remainder takes the sign of the dividend a. For example -5 mod 2 = -1 here, whereas the alternative "floored" convention (shown as a secondary output) gives 1, taking the sign of the divisor instead.
$$\begin{gathered} r = \text{a} - q \cdot \text{b} \\[1.5em] \text{where}\quad \left\{ \begin{aligned} q &= \operatorname{trunc}\!\left( \dfrac{\text{a}}{\text{b}} \right) \\ \text{b} &\neq 0 \end{aligned} \right. \end{gathered}$$
Worked example
For a = 5, b = 2: the quotient is trunc(5/2) = trunc(2.5) = 2, and the remainder is 5 - 2x2 = 1. Proof: 5 div 2 = 2 R 1, and 2 x 2 + 1 = 5. So 5 mod 2 = 1. A decimal case: 7.5 mod 2 gives trunc(3.75) = 3 and 7.5 - 3x2 = 1.5.
$$\operatorname{trunc}(5/2) = \operatorname{trunc}(2.5) = 2$$$$5 - 2 \times 2 = 1$$$$2 \times 2 + 1 = 5$$$$5 \bmod 2 = 1$$$$7.5 \bmod 2 \;\Rightarrow\; \operatorname{trunc}(3.75) = 3 \quad\text{and}\quad 7.5 - 3 \times 2 = 1.5$$FAQ
Why is -5 mod 2 = -1 and not 1? This tool follows the programming-language truncated convention, so the remainder matches the sign of the dividend. The floored-modulo row shows the math-convention answer (1) when you need the divisor's sign.
How do I test divisibility? A number x is a multiple of b exactly when x mod b = 0. For example 496 mod 4 = 0 (a multiple) but 226 mod 4 = 2 (not a multiple).
Can the divisor be zero? No. Division by zero is undefined, so the calculator returns an error if b = 0.