Modulo

Remainder of a ÷ b.

a mod b
2

How to Use the Modulo Calculator

  1. Enter the **dividend** (a) — the number you want to divide — into the first input field.
  2. Enter the **divisor** (n) — the number you are dividing by — into the second input field. It must not be zero.
  3. Click **Calculate** (or press Enter) to compute the result.
  4. The calculator displays the **remainder r**, along with the full equation: a = n × q + r.
  5. To start a new calculation, click **Reset** and enter new values.

Modulo Formula

r = a − n × ⌊a / n⌋

The modulo operation finds the remainder r when dividend a is divided by divisor n. The standard mathematical definition uses the floor function to guarantee a non-negative result consistent with most programming languages and calculators:

r = a − n × ⌊a / n⌋

Equivalently, r is the unique integer satisfying:

  • a = n × q + r
  • 0 ≤ r < |n|

where q is the integer quotient (floor division). This formulation ensures the remainder is always between 0 (inclusive) and |n| (exclusive).

  • r — The remainder (result of the modulo operation). Always satisfies 0 ≤ r < |n|.
  • a — The dividend — the number being divided. Can be any integer (positive, negative, or zero).
  • n — The divisor (modulus) — the number you are dividing by. Must be a non-zero integer.
  • q — The integer quotient, equal to ⌊a / n⌋ (floor of a divided by n). This is not the final answer but an intermediate step.
  • ⌊ ⌋ — The floor function — rounds a value down to the nearest integer (toward negative infinity).

Worked Example: 47 mod 6

Dividend (a) = 47, Divisor (n) = 6
Step 1 — Divide: 47 ÷ 6 = 7.8333…
Step 2 — Floor: ⌊7.8333…⌋ = 7  (integer quotient q)
Step 3 — Multiply: 6 × 7 = 42
Step 4 — Subtract: 47 − 42 = 5

Result: 47 mod 6 = **5** (Check: 6 × 7 + 5 = 42 + 5 = 47 ✓)

What Your Result Means

The result 5 means that when 47 is divided by 6, the division goes in evenly 7 times (producing 42) and leaves a leftover — or remainder — of 5. The remainder is always a whole number that is smaller than the absolute value of the divisor. If the remainder were 0, it would mean the dividend is exactly divisible by the divisor (i.e., 6 is a factor of 47 — which it is not in this case).

Understanding Modulo

What Is the Modulo Operation?

The modulo operation (often written as mod or %) is a basic arithmetic operation that returns the remainder after integer division. It is a close companion to regular division, but instead of returning the quotient, it returns what is left over.

Everyday Analogy

Imagine a 12-hour clock. If it is currently 10 o'clock and you add 5 hours, you get 15, but clocks only go up to 12, so the actual time is 3 o'clock — because 15 mod 12 = 3. This cyclic "wrap-around" behaviour is the core idea behind modulo.

Key Properties

  • a mod n = 0 means n divides a evenly (n is a factor of a).
  • a mod 1 = 0 for any integer a (everything divides by 1 with no remainder).
  • a mod a = 0 for any non-zero a.
  • a mod n = a when |a| < |n| (the dividend is smaller than the divisor).
  • Modulo is not the same as the absolute value of the remainder from truncated division (important for negative numbers in some programming languages).

Negative Numbers

Behaviour with negative dividends or divisors varies by convention. The floored division convention (used here and in Python) always returns a non-negative remainder. For example, −7 mod 3 = 2, because −7 = 3 × (−3) + 2. Some languages (like C, Java, JavaScript) use truncated division, giving −7 % 3 = −1 instead.

Real-World Applications

  • Programming: Loop cycling, array index wrapping, determining even/odd (n % 2).
  • Cryptography: RSA encryption, hashing, and elliptic curve algorithms all rely heavily on modular arithmetic.
  • Calendar calculations: Finding the day of the week for any date (Zeller's Congruence uses mod).
  • Checksums & error detection: ISBN, IBAN, and barcode check digits use mod 10 or mod 11.
  • Music theory: Octave equivalence in pitch class notation uses mod 12.
  • Game development: Sprite animation frame cycling, procedural world generation.

Common Mistakes

  • **Dividing by zero**: The modulo operation is undefined when the divisor n = 0. Always ensure your divisor is non-zero.
  • **Confusing mod with integer division**: Mod returns the *remainder*, not the quotient. 17 mod 5 = 2, not 3.
  • **Assuming the result is always positive**: With truncated division (used in C, Java, JavaScript), a negative dividend yields a negative remainder. This calculator uses floored division, which always gives a non-negative result.
  • **Mixing up dividend and divisor**: Order matters. 7 mod 3 = 1, but 3 mod 7 = 3. Always put the number being divided first.
  • **Expecting a decimal result**: Modulo always returns an integer remainder. If you need the fractional part of a division, use a different operation.
  • **Confusing modulo with modulus**: In common usage these terms overlap, but in some contexts 'modulus' refers to the divisor n itself, not the result r.

Common Questions About Modulo

How do I check if a number is even or odd using modulo?

Divide the number by 2 using modulo. If n mod 2 = 0, the number is even. If n mod 2 = 1, the number is odd. For example, 14 mod 2 = 0 (even) and 15 mod 2 = 1 (odd).

How does modulo apply to finding the day of the week?

Many day-of-week algorithms use modulo 7. For instance, if today is day 3 (Wednesday) and you want to know what day it will be in 100 days: (3 + 100) mod 7 = 103 mod 7 = 5, which corresponds to Friday (if 0 = Sunday).

What is the greatest common divisor (GCD) connection to modulo?

The Euclidean algorithm for finding the GCD of two numbers is built entirely on the modulo operation: GCD(a, b) = GCD(b, a mod b), repeated until the remainder is 0. The last non-zero remainder is the GCD.

How does modulo work with very large numbers?

Modulo works identically for large numbers — just apply the formula r = a − n × ⌊a/n⌋. In cryptography, extremely large modulo operations (e.g., 2^1024 mod p) are computed efficiently using modular exponentiation algorithms.

Is 0 mod n defined?

Yes. 0 divided by any non-zero number n gives a quotient of 0 and a remainder of 0. So 0 mod n = 0 for all n ≠ 0.

Frequently Asked Questions

What is the difference between mod and remainder?

In everyday math they are the same. However, in computing, 'remainder' sometimes refers to the result of truncated division (which can be negative), while 'mod' (using floored division) is always non-negative. For positive inputs the two are identical.

Can I use this calculator with decimal (non-integer) numbers?

The classical modulo operation is defined for integers. Many calculators extend it to real numbers using the formula r = a − n × ⌊a/n⌋, so inputs like 7.5 mod 2.5 = 0 are valid. However, for most programming and mathematical contexts, modulo is used exclusively with integers.

What does it mean when the result is 0?

A result of 0 means the dividend is exactly divisible by the divisor — there is no remainder. For example, 12 mod 4 = 0 because 12 ÷ 4 = 3 exactly. This is how you test for divisibility or check whether a number is even (n mod 2 = 0).

How is mod written in different programming languages?

The percent sign % is the modulo operator in most languages: Python, C, Java, JavaScript, and C++ all use %. However, Python uses floored division (always non-negative result), while C, Java, and JavaScript use truncated division (result can be negative for negative inputs). In Excel and Google Sheets, use the MOD() function.

What is modular arithmetic?

Modular arithmetic is a system of arithmetic where numbers 'wrap around' after reaching a certain value called the modulus. It is essentially extended repeated use of the modulo operation. The integers 0, 1, 2, …, n−1 form a complete residue system modulo n. It is foundational in number theory and cryptography.

Related Calculators

Sources

Only sources that have been reviewed are shown. Unverified citations are never published.

Spotted a calculation error?Report an Error
How this calculator works:MethodologyReport an Error

Report an issue or suggest a feature

Spotted an inaccuracy or have an idea to improve this calculator? Let us know.

We use cookies to operate the site, and — with your consent — to show advertising and measure usage. You can change your choice anytime in Cookie Settings.

Manage options