Skip to content
Calc.

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: September 2026

a mod b (floored: Python, Excel MOD)

2

Formula below · 3 sources (khanacademy.org, developer.mozilla.org, docs.python.org) · Updated Sep 2026

Compare with similar

About this calculator

The modulo operation gives the remainder r left when a is divided by b: a = b × q + r, where q is a whole-number quotient. For positive numbers every convention agrees: 17 mod 5 = 2, because 17 = 5 × 3 + 2. With negative numbers the conventions differ, because they round the quotient differently. Floored modulo rounds a ÷ b down, so the remainder takes the sign of the divisor: −7 mod 3 = 2. This is what mathematicians usually mean, and what Python's %, Excel's MOD and Ruby use. Truncated modulo rounds the quotient toward zero, so the remainder takes the sign of the dividend: −7 % 3 = −1 in JavaScript, C, C++, Java and C#. Euclidean modulo always gives 0 ≤ r < |b|, whatever the signs. The headline result is the floored remainder; the tiles show the quotient and the truncated and Euclidean remainders, which differ only when a or b is negative. The calculator also accepts decimals (5.5 mod 2 = 1.5). Modulo is the arithmetic of anything that wraps around: clocks and weekdays, array indices, hash tables, check digits (Luhn, ISBN) and the modular arithmetic behind RSA and Diffie–Hellman.

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. Example 3 — a negative dividend. −7 mod 3: the floored result is 2 (q = −3, since 3 × −3 + 2 = −7); the truncated tile shows −1 (3 × −2 − 1 = −7), the value JavaScript's −7 % 3 returns. Use the figure that matches the language or textbook you are checking against.

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. In mathematics the remainder for a positive divisor is taken 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, Ruby and Excel's MOD floor the quotient instead: -7 % 3 = 2. The calculator shows the floored result and, in the tiles, the truncated and Euclidean remainders. In JavaScript or C, ((a % b) + b) % b turns the truncated remainder into the floored one for a positive divisor.

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 convention; the calculator shows all three. Truncated (JavaScript, C, Java): the result has the sign of the dividend, so −7 % 3 = −1, 7 % −3 = 1, −7 % −3 = −1. Floored (Python, Excel MOD): the result has the sign of the divisor, so −7 % 3 = 2 and 7 % −3 = −2. Euclidean: always non-negative, so −7 mod 3 = 2 and 7 mod −3 = 1. The difference causes subtle bugs when code is ported between languages or used with negative array indices.

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 symbolic expressions, which need a computer algebra system. It does not find modular inverses (x with a·x ≡ 1 mod n) or compute large powers mod n; use the modular arithmetic calculator for those. Inputs are ordinary floating-point numbers, so integers above 2⁵³ (about 9 × 10¹⁵) lose precision; very large cryptographic numbers need BigInt or a big-integer library.

Related calculators

Sources & references

How we check our calculators

Think a result is wrong? Report a problem with this calculator.