🔢 Modulo Calculator – Remainders, Euclidean Mod & Modular Arithmetic
The modulo operation finds the remainder left over after dividing one number by another. It is one of the most frequently used operations in mathematics and computer science, appearing in everything from clock arithmetic and cryptography to game loops and hash functions.
How the Modulo Operation Works
Given a dividend a and a divisor b, integer division produces a quotient q and a remainder r such that:
a = b × q + rThe remainder r is what the modulo operator returns. For example, 29 mod 6 = 5 because 29 = 6 × 4 + 5.
Standard vs. Euclidean Modulo
Most programming languages use truncation-based division, which can yield a negative remainder when the dividend is negative:
-29 mod 6 → -5 (JavaScript, C, Java)Euclidean modulo always returns a non-negative result by using the floor function:
r = a − b × floor(a / b)-29 mod 6 → 1 (Euclidean)This is mathematically preferred because the remainder is always in the range [0, |b|), making it easier to reason about congruence classes.
Calculation Modes
| Mode | What it computes | Example |
|---|---|---|
| Standard | Truncation-based remainder (matches most languages) | 29 mod 6 = 5 |
| Euclidean | Always non-negative remainder via floor division | −29 mod 6 = 1 |
| Quotient | Integer quotient and remainder together | q = 4, r = 5 |
| Congruence | Tests whether a ≡ b (mod n) | 29 ≡ 5 (mod 6) ✓ |
| Range Wrap | Maps a value into a cyclic range [start, end) | wrap(26, 0, 24) = 2 |
Congruence and Modular Arithmetic
Two integers a and b are congruent modulo n — written a ≡ b (mod n) — if their difference a − b is divisible by n. Equivalently, they share the same Euclidean remainder when divided by n. Modular arithmetic underlies RSA encryption, calendar calculations, and cyclic group theory.
Clock Arithmetic and Range Wrapping
Range wrapping uses modulo to fold a value back into a fixed interval. The general formula for wrapping into [start, end) is:
wrapped = start + ((value − start) mod (end − start))Practical uses include 24-hour clock rollover (span = 24), weekday cycling (span = 7), RGB channel wrapping, and array-index rotation in circular buffers.
Batch Evaluation
The batch feature applies one modulus to a list of dividends simultaneously and presents the results in a sortable table. This is useful for checking divisibility patterns, constructing modular sequences, or validating checksums across many values at once.
Common Applications
- Programming:
index % arrayLengthfor safe circular indexing; even/odd detection withn % 2. - Cryptography: Modular exponentiation powers RSA, Diffie-Hellman, and elliptic-curve algorithms.
- Calendars: Zeller's congruence and ISO weekday formulas use mod 7.
- Checksums: ISBN-13, credit-card Luhn algorithm, and EAN barcodes all rely on modular arithmetic.
- Hashing: Hash tables map keys to buckets with
hash(key) % tableSize.
Sign Conventions Across Languages
Different languages treat negative dividends differently. JavaScript's % operator and C's % follow truncation (result has the sign of the dividend). Python's % and Haskell's mod follow floor division (result always non-negative for a positive modulus), matching the Euclidean definition. Use the Euclidean mode in this calculator for math-consistent, language-neutral results.