03 · UNDERSTAND THE METHOD
How the modulo calculator works
Modular arithmetic groups integers by the remainder they leave after division by a positive modulus. It is often described through a clock, where adding hours wraps around a fixed cycle. This calculator returns the nonnegative residue from zero through one less than the modulus, including when the original integer is negative. That convention is useful for cyclic indexing and differs from programming languages that preserve the dividend’s sign in a remainder operation.
The formula and its variables
- a
- Signed integer being reduced.
- m
- Positive integer modulus or cycle length.
- r
- Nonnegative remainder, also called the residue.
The calculation, step by step
- Enter an integer and a strictly positive integer modulus. A zero modulus cannot define division or a remainder.
- Find a remainder and normalize it into the interval beginning at zero and ending just below the modulus. This normalization matters for negative dividends.
- Check that subtracting the residue from the original integer leaves an exact multiple of the modulus. Interpret that multiple as a whole number of cycles.
A worked example
For 29 modulo 12, two whole cycles account for 24 and the residue is 5. For −5 modulo 12, the nonnegative residue is 7 because −5 = (−1 × 12) + 7. Both −5 and 7 belong to the same class modulo 12. A multiple such as 36 modulo 12 produces zero rather than twelve, because residues are always smaller than the modulus.
| Integer dividend | 29 |
|---|---|
| Positive integer modulus | 12 |
| Nonnegative remainder | 5 |
How to read the result and visual
The residue identifies a position within a cycle, while the original integer can count multiple cycles in either direction. Values differing by a whole multiple of the modulus share the same residue. This page labels positions numerically from zero; a wall clock often labels its zero position as twelve, so adapt that final display convention when explaining time.
Assumptions, rounding, and limitations
Inputs must be whole numbers in the supported exact numeric range. The tool calculates one reduction, not modular inverses, modular exponentiation, or a cryptographic protocol. Its nonnegative convention may differ from a spreadsheet or programming language’s raw remainder operator for negative inputs. Decimal division should be handled with a different calculator.
Frequently asked questions
Why is −5 modulo 12 equal to 7?
Adding one twelve-unit cycle to −5 reaches the equivalent nonnegative position seven.
Can a remainder equal the modulus?
No. An additional full cycle would be removed, leaving zero in that case.