Use this free residue calculator to find the least non-negative residue of an integer modulo n, write the division form, and check congruence between two numbers.
Residue (Modulo) Calculator
Enter integers only. Modulus must be positive.
What is a residue in modular arithmetic?
In modular arithmetic, the residue of an integer a modulo n is the remainder left after division by n. Most textbooks and calculators report the least non-negative residue, which always lies between 0 and n - 1 when n > 0.
Here, q is an integer quotient and r is the residue. For example, if a = 29 and n = 6, then: 29 = 6(4) + 5, so the residue is 5.
Why residues matter
Residues appear in many practical and academic settings:
- Cryptography: RSA and many security algorithms rely on modular arithmetic.
- Computer science: Hash tables, cyclic buffers, and indexing patterns use modulo behavior.
- Number theory: Congruences, divisibility tests, and Diophantine reasoning all depend on residues.
- Scheduling and cycles: Weekly rotations, repeating events, and clock arithmetic are naturally modular.
How this residue calculator works
This calculator computes:
- The least non-negative residue of a mod n.
- The quotient q in the identity a = nq + r.
- An optional congruence check between a and b modulo n.
Handling negative integers correctly
Negative numbers often cause confusion because programming languages can display negative remainders. Mathematically, for modulus n > 0, the preferred residue is always in the interval [0, n-1]. That is why this tool normalizes the value and returns the least non-negative result.
Examples
Example 1: Positive integer
Let a = 83 and n = 9.
83 = 9(9) + 2, so residue(83 mod 9) = 2.
Example 2: Negative integer
Let a = -37 and n = 12.
We can write -37 = 12(-4) + 11, so residue(-37 mod 12) = 11.
Example 3: Congruence check
Are 52 and 10 congruent modulo 7?
52 mod 7 = 3 and 10 mod 7 = 3, so yes: 52 ≡ 10 (mod 7).
Common mistakes to avoid
- Using modulus 0 (undefined operation).
- Mixing decimal numbers with integer modular arithmetic.
- Forgetting to normalize negative remainders.
- Assuming equal difference means congruent without checking divisibility by n.
Quick FAQ
Is residue the same as remainder?
In most modular arithmetic contexts, yes—especially when expressed as the least non-negative representative.
Can modulus be negative?
Some advanced contexts allow it, but standard elementary modular arithmetic uses a positive modulus. This calculator enforces n > 0 for clarity and consistency.
What does a ≡ b (mod n) mean?
It means n divides (a - b), or equivalently, a and b have the same residue modulo n.
Final takeaway
A residue calculator is a fast way to verify modulo calculations, test congruences, and avoid sign mistakes. If you work with number theory, cryptography, coding interviews, or algorithm design, mastering residues is a high-leverage skill.