Modulo Calculator
Compute a mod b — the remainder when dividend a is divided by divisor b. Foundational for clock arithmetic, cyclic patterns, hashing, parity tests, modular arithmetic in cryptography, and any "wrap-around" computation.
Last updated: May 2026
Compare with similar
About this calculator
The modulo (or "mod") operation returns the remainder of integer division. Formally, for integers a (dividend) and b (divisor, b ≠ 0), the modulo r satisfies a = b·q + r, where q is the quotient and r is the remainder. By convention 0 ≤ r < |b| in mathematical contexts, but most programming languages (including JavaScript, used here) define a % b to take the sign of the dividend a, so a % b can be negative when a is negative. This calculator implements JavaScript's % operator directly. Variables: a is the dividend, b is the non-zero divisor. Edge cases: b = 0 is undefined (division by zero — JavaScript returns NaN); for floating-point inputs JavaScript still applies %, returning a "remainder" derived from the fractional part (e.g., 5.5 % 2 = 1.5). Negative numbers: in JavaScript -7 % 3 = -1, while the "mathematical" mod gives 2; if you need always-non-negative remainders use ((a % b) + b) % b. The modulo operation is the bedrock of cyclic arithmetic — telling time on a 12-hour clock, computing day-of-week, validating credit-card numbers via Luhn, generating pseudo-random numbers, and implementing hash tables all rely on it. Every theorem in elementary number theory (Fermat's little, Euler's, CRT) is stated in terms of congruences modulo n. The relationship a ≡ b (mod n) means a − b is divisible by n; modulo defines an equivalence relation that partitions the integers into n disjoint classes.
How to use
Example 1 — Even/odd test. Is 17 even or odd? Compute 17 mod 2. Enter Dividend = 17, Divisor = 2. Result: 1. ✓ Remainder 0 means even; remainder 1 means odd. So 17 is odd. This is the simplest application of modulo: parity testing is universal in programming (`if (n % 2 === 0)`), in mathematics (proofs about even and odd numbers), and in everyday life (alternating items, scheduling). Example 2 — Day of the week arithmetic. Today is Monday (day index 1, where Sunday = 0). What day will it be in 100 days? Compute 100 mod 7. Enter Dividend = 100, Divisor = 7. Result: 2. ✓ So 100 days from Monday is Monday + 2 days = Wednesday. The whole calendar runs on modular arithmetic: weekdays repeat mod 7, hours repeat mod 24 (or mod 12 if you ignore AM/PM), months mod 12. Any "what comes back to the start every N steps?" question is a modulo question.
Frequently asked questions
What is the difference between modulo and remainder?
In mathematics they are usually treated as synonymous — both refer to what is left over after division. But programming languages distinguish them when the operands have different signs. The mathematical mod is defined to always return a non-negative result in [0, |b|), so -7 mod 3 = 2 (because -7 = 3·(-3) + 2). Most C-family programming languages (including JavaScript, Java, C, C++) use a "remainder" definition where the result takes the sign of the dividend: -7 % 3 = -1. Python and a handful of other languages use the mathematical definition: -7 % 3 = 2. This calculator uses JavaScript's definition. To convert from the JavaScript result to the mathematical result, use ((a % b) + b) % b.
Why is modulo so important in computer science and cryptography?
Modular arithmetic is everywhere in computing because it naturally describes cyclic and bounded systems: array indexing (modulo N to wrap around), hash tables (modulo bucket count), pseudo-random number generators (linear congruential generators), checksums (mod 10 for Luhn, mod 11 for ISBN), and clock arithmetic. In cryptography, modulo is the core operation: RSA encryption works in ℤ/nℤ where n is a product of two large primes; Diffie-Hellman key exchange operates modulo a prime; elliptic curve cryptography uses modulo a prime to define a finite field. The security of these schemes depends on the difficulty of "inverse" operations under modulo — discrete logarithm, modular square roots, factorisation — which are computationally hard despite the forward operations being easy.
How does modulo work with negative numbers?
It depends on the language or convention. JavaScript (which this calculator uses) returns a result with the same sign as the dividend: -7 % 3 = -1, 7 % -3 = 1, -7 % -3 = -1. Python uses the divisor's sign: -7 % 3 = 2, 7 % -3 = -2. The mathematical convention (used in number theory) always returns a non-negative result in [0, |b|): -7 mod 3 = 2. For most practical purposes in JavaScript or C, if you want the always-non-negative mathematical mod, use ((a % b) + b) % b. The discrepancy can cause subtle bugs when porting code between languages, when working with negative array indices, or when implementing cryptographic algorithms — always double-check which convention your language and library use.
What are the most common mistakes people make with modulo?
The first is dividing by zero — a % 0 is undefined and produces NaN in JavaScript or a runtime error in most languages. The second is forgetting the sign behaviour with negative dividends; using % on negative inputs without thinking can produce off-by-one errors in code that assumes non-negative remainders. The third is confusing % with /: integer division gives the quotient, modulo gives the remainder, and they are complementary operations. The fourth is using % on floating-point inputs and expecting integer behaviour — 5.5 % 2 is 1.5, not an error, but it may not be what you wanted. The fifth is comparing modulo results to a constant without accounting for the divisor's magnitude (`if (a % 100 == 1)` is a different test than `if (a % 1000 == 1)`, even though both have a 1 in the result). Finally, in cryptography contexts, taking the modulo too early can leak information about the intermediate value through timing side-channels; constant-time modular operations are an entire subfield.
When should I not use this calculator?
Skip it for non-integer "mod" operations on irrational numbers or symbolic expressions — those need a CAS, not a numeric calculator. Do not use it for the strict "mathematical mod" with always-non-negative results on negative inputs without adjusting the output as described above. It is the wrong tool for modular inverse computation (finding x such that a·x ≡ 1 mod n); that requires the extended Euclidean algorithm or Fermat's little theorem, neither of which is what % computes. Avoid it for modular exponentiation on large numbers (a^b mod n with b in the thousands or more) — naive computation overflows; use exponentiation by squaring with reduction at each step. Finally, do not use raw % for cryptographic operations on big integers in JavaScript — its Number type loses precision above 2⁵³ − 1, so use BigInt or a dedicated big-integer library for any real cryptographic work.