Modulo Calculator
Compute a mod n for any numbers, with truncated and Euclidean remainders.
Written by Golam Rabbani, Founder & Lead Engineer
How to use this modulo calculator
- Enter the dividend (a) in the first field.
- Enter the divisor (n) in the second field — must not be zero.
- Press Calculate to see a mod n, the quotient, and the Euclidean remainder.
- Use Copy to put the result on your clipboard, or Reset to clear the inputs.
About this modulo calculator
The modulo calculator computes the remainder when a number a is divided by a number n. It shows both the truncated remainder (the same convention used by JavaScript, C, and most modern languages) and the Euclidean remainder, which is always non-negative.
The formula is a mod n = a − (trunc(a ÷ n) × n). For example, 17 mod 5 has trunc(17 ÷ 5) = 3, so the remainder is 17 − (3 × 5) = 17 − 15 = 2. Both 17 and 5 are positive, so the two conventions agree at 2. They differ for negative inputs: −7 mod 3 with truncated division is −7 − (−2 × 3) = −1, while the Euclidean remainder is 2 (the smallest non-negative value congruent to −7 modulo 3). The tool accepts decimal inputs as well as integers and rejects a divisor of zero.
Modulo arithmetic is the backbone of cryptography, hashing, cyclic patterns, and any problem that wraps around (clocks, calendars, ring buffers).
FAQ
- What does the modulo calculator do?
- It returns the remainder after dividing a by n, showing both the truncated remainder (matches the JavaScript % operator) and the Euclidean remainder (always non-negative).
- What formula does the calculator use?
- For the truncated remainder: a mod n = a − (trunc(a ÷ n) × n). The Euclidean remainder is ((a mod |n|) + |n|) mod |n|, which forces the result into the range [0, |n|).
- Why are there two remainders?
- Different fields prefer different conventions. Most programming languages truncate division, so the remainder shares the sign of the dividend. Number theory prefers the Euclidean version because it is always non-negative.
- What happens if the divisor is zero?
- The tool returns an error. Division by zero is undefined, so a mod 0 has no value.
- Does this tool store my numbers?
- No. The calculation runs entirely in your browser; nothing is sent to a server or saved between visits.
- Is the modulo calculator free?
- Yes. It is free to use with no signup, no account, and no usage limit.