Modulo Calculator
Modulo calculator to compute a mod n, return the remainder of integer division, handle negative numbers, and check modular congruence. Includes batch tables and step-by-step explanation.
Full original guide (expanded)
Modulo Calculator
Compute a mod n, return the integer remainder of division, handle negative numbers, and check modular congruence. Includes a batch mode for modulo tables.
Interactive modulo and remainder calculator
Use this tool to compute the remainder of integer division (a mod n), understand Euclidean division a = q·n + r, and verify congruences a ≡ b (mod n). The calculator always uses the Euclidean definition of modulo, so the remainder r is between 0 and n − 1 for n > 0, even if a is negative.
Dividend a
You can enter positive or negative integers.
Modulus n
Must be a positive integer. The calculator enforces n > 0.
Optional comparison b
Leave empty if you only need a single modulo result.
What is modulo?
In arithmetic, the modulo (or mod) operation returns the remainder when one integer is divided by another positive integer. When we write \[ a \bmod n, \] we mean the remainder r that appears in the Euclidean division of a by n:
\[ a = q n + r, \quad \text{with } q \in \mathbb{Z},\; 0 \le r < n. \]
For example, 17 mod 5 = 2 because 17 = 3 × 5 + 2 and 2 lies in the interval [0, 5). The calculator implements exactly this definition.
Euclidean division and remainder
For integers a and n > 0, Euclid's division theorem guarantees that there exist unique integers q (quotient) and r (remainder) such that:
\[ a = q n + r \quad \text{and} \quad 0 \le r < n. \]
In this calculator:
- You enter a and n as integers with n > 0.
- The tool solves for q and r.
- The displayed value of a mod n is exactly r.
If a is negative, q will also be negative in such a way that r stays between 0 and n − 1. For instance, −7 mod 5 = 3 because −7 = (−2) × 5 + 3.
Modulo with negative numbers
When you compute modulo by hand or in pure math, the remainder is defined to be non-negative and less than n. However, some programming languages use a raw remainder operator that follows the sign of the dividend, which can create confusion when a is negative.
This calculator always follows the Euclidean convention:
\[ r = a - n \left\lfloor \frac{a}{n} \right\rfloor, \quad 0 \le r < n. \]
That is why you may see results like −1 mod 5 = 4 or −7 mod 5 = 3. These are the standard values in modular arithmetic and make many theorems and identities work cleanly.
Modular congruence a ≡ b (mod n)
Two integers a and b are said to be congruent modulo n if they leave the same remainder when divided by n. Formally:
\[ a \equiv b \pmod{n} \quad \Longleftrightarrow \quad n \mid (a - b) \quad \Longleftrightarrow \quad a \bmod n = b \bmod n. \]
Typical examples:
- 17 ≡ 2 (mod 5), because both have remainder 2 mod 5.
- −1 ≡ 4 (mod 5), because −1 mod 5 = 4.
- 8 ≡ 0 (mod 4), because 4 divides 8 exactly.
The congruence checker in this calculator compares a and b modulo n and reports whether they are congruent, including their canonical remainders.
Practical uses of modulo
Modulo arithmetic appears in many applications:
- Clock arithmetic: hours wrap around every 12 or 24.
- Computer science: hashing, cyclic buffers, and random number generators.
- Number theory: studying primes, residues, and patterns in integers.
- Scheduling and repetition: events occurring every n days, positions in cycles.
The batch table mode helps you spot repeating patterns such as cycles of residues in these contexts.
Modulo calculator – FAQ
Can I use non-integer numbers in the modulo calculator?
No. The standard definition of modulo is based on integer division, so this calculator requires that a and n be integers and n > 0. If you need floating-point remainders, consider scaling your values to integers or using a different tool tailored to real numbers.
What happens if I enter n = 0?
Division by zero is undefined, so modulo with n = 0 is also undefined. The calculator will return an error and ask you to choose a positive integer modulus instead.
Why do some programming languages give a negative result for a % n?
Many languages implement the % operator as a remainder that keeps the sign of a.
For example, in some environments −7 % 5 = −2. Mathematically, however, it is often more convenient
to use the Euclidean remainder 3. This tool uses the mathematical convention so that
modular identities and congruence rules behave as expected.
How large can the numbers be?
The limit is essentially the range of standard JavaScript integers. For everyday modular arithmetic, cryptography exercises, and classroom examples, this range is more than sufficient. Extremely large inputs may lose precision due to the underlying floating-point representation.
Can I export the modulo table?
The batch table is designed for quick on-screen inspection. To export results, you can copy the table rows into a spreadsheet or text editor and convert them into CSV or another format suitable for your workflow.
Frequently Asked Questions
How should I interpret the quotient and remainder?
The quotient q tells you how many whole copies of n fit inside a, while the remainder r tells you what is left over. Together they satisfy a = q·n + r with 0 ≤ r < n. The modulo result is simply this remainder r.
Why does the calculator sometimes show large negative quotients?
When a is negative, the quotient q may also be negative to keep the remainder r in the interval [0, n). This is normal in Euclidean division and does not affect the correctness of the modulo result.
Is this calculator suitable for modular arithmetic in number theory?
Yes. Because it enforces the Euclidean definition of remainder, the results are consistent with standard number theory textbooks and proofs. You can safely use it to check modular equations and congruences.
Formula (LaTeX) + variables + units
a \bmod n,
a = q n + r, \quad \text{with } q \in \mathbb{Z},\; 0 \le r < n.
a = q n + r \quad \text{and} \quad 0 \le r < n.
r = a - n \left\lfloor \frac{a}{n} \right\rfloor, \quad 0 \le r < n.
a \equiv b \pmod{n} \quad \Longleftrightarrow \quad n \mid (a - b) \quad \Longleftrightarrow \quad a \bmod n = b \bmod n.
','\
\[ a = q n + r, \quad \text{with } q \in \mathbb{Z},\; 0 \le r < n. \]
\[ a = q n + r \quad \text{and} \quad 0 \le r < n. \]
\[ r = a - n \left\lfloor \frac{a}{n} \right\rfloor, \quad 0 \le r < n. \]
\[ a \equiv b \pmod{n} \quad \Longleftrightarrow \quad n \mid (a - b) \quad \Longleftrightarrow \quad a \bmod n = b \bmod n. \]
- No variables provided in audit spec.
- NIST — Weights and measures — nist.gov · Accessed 2026-01-19
https://www.nist.gov/pml/weights-and-measures - FTC — Consumer advice — consumer.ftc.gov · Accessed 2026-01-19
https://consumer.ftc.gov/
Last code update: 2026-01-19
- Initial audit spec draft generated from HTML extraction (review required).
- Verify formulas match the calculator engine and convert any text-only formulas to LaTeX.
- Confirm sources are authoritative and relevant to the calculator methodology.