Modulo Calculator

Modulo Calculator

Growing AI Skill PRO

Enter Calculation

Formula

r=Dividend−Divisor·⌊DividendDivisor⌋r = \text{Dividend} - \text{Divisor} \cdot \left\lfloor \frac{\text{Dividend}}{\text{Divisor}} \right\rfloor
Usage stats

Advertisement

Results

Remainder: 2
17÷5=3.4
Quotient 3.4
Remainder 2

Report an error on this page

What is a Modulo Calculator?

A modulo calculator is a mathematical tool that computes the remainder when one number (the dividend) is divided by another number (the divisor). The modulo operation, represented by the % symbol in many programming languages, finds the remainder after division.

When to Use a Modulo Calculator

The modulo operation has various practical applications:

  • In computer programming for implementing cyclic behavior, such as generating random numbers within a range
  • For checking if a number is odd or even (n % 2 = 0 for even numbers)
  • In cryptography and hash functions to ensure values fall within specific ranges

How to Calculate Modulo

Advertisement

The modulo operation follows this formula:

a mod b = a - b × floor(a ÷ b)

Where:

  • a is the dividend (the number being divided)
  • b is the divisor (the number dividing a)
  • floor(x) rounds x down to the nearest integer

For integers, the modulo is simply the remainder after division. For decimal numbers, we first calculate the quotient, round it down to the nearest integer, and then find the remainder.

Examples

Example 1: Basic Integer Modulo

Find the result of 17 mod 5

Dividend (a) Divisor (b) Calculation Result
17 5 17 - 5 × floor(17 ÷ 5) = 17 - 5 × 3 = 17 - 15 2

Example 2: Negative Dividend

Find the result of -13 mod 4

Dividend (a) Divisor (b) Calculation Result
-13 4 -13 - 4 × floor(-13 ÷ 4) = -13 - 4 × (-4) = -13 + 16 3

Example 3: Decimal Numbers

Find the result of 7.5 mod 2.2

Dividend (a) Divisor (b) Calculation Result
7.5 2.2 7.5 - 2.2 × floor(7.5 ÷ 2.2) = 7.5 - 2.2 × 3 = 7.5 - 6.6 0.9

Related Calculators

Explore other mathematical calculators that might be useful for your calculations:

Advertisement

Definitions & Glossary

The modulo operation returns what is left over after one number is divided by another. The terms below describe every part of that operation and the two conventions used for negative numbers.

  • Dividend (\(a\)) — the number being divided; the first input of \(a \bmod b\).
  • Divisor (\(b\)) — the number you divide by, also called the modulus when the context is congruence arithmetic.
  • Quotient — how many whole times the divisor fits into the dividend. In the floored convention it is \(\left\lfloor a/b \right\rfloor\); in the truncated convention it is the division result with its fractional part cut off toward zero.
  • Remainder (\(r\)) — what is left after removing the whole multiples of the divisor: \(r = a - b \cdot q\), where \(q\) is the chosen quotient.
  • Modulus (\(n\)) — the divisor viewed as the size of a cyclic system, e.g. \(n = 12\) for a 12-hour clock, \(n = 7\) for days of the week.
  • Floor function \(\left\lfloor x \right\rfloor\) — the greatest integer not exceeding \(x\). It rounds down (toward \(-\infty\)), so \(\left\lfloor 3.25 \right\rfloor = 3\) but \(\left\lfloor -3.25 \right\rfloor = -4\).
  • Congruence \(a \equiv r \pmod n\) — read "\(a\) is congruent to \(r\) modulo \(n\)", meaning \(n\) divides \(a - r\) exactly. For example \(17 \equiv 2 \pmod 5\) because \(17 - 2 = 15\) is a multiple of 5.
  • Floored modulo — uses \(q = \left\lfloor a/b \right\rfloor\), so the result always takes the sign of the divisor. This is the convention used by this calculator: $$r = a - b \cdot \left\lfloor \frac{a}{b} \right\rfloor$$
  • Truncated remainder — uses \(q = \operatorname{trunc}(a/b)\), so the result takes the sign of the dividend. The two conventions agree whenever \(a\) and \(b\) have the same sign or the division is exact; they differ by exactly \(b\) otherwise.
  • The % operator — the symbol most programming languages use for this operation. It is not standardized across languages: some implement floored modulo, others truncated remainder (see the next section). Some languages instead spell it mod, MOD or rem.

Divisor 0 is undefined. Because \(a \bmod 0\) would require dividing by zero, it has no value. Most languages raise an error (Python ZeroDivisionError, Java ArithmeticException), spreadsheets return an error value such as #DIV/0!, and IEEE 754 floating-point remainder returns NaN.

Number line showing repeated subtraction of the divisor from the dividend leaving a remainder
Modulo as repeated subtraction: the remainder is what is left after removing whole multiples of the divisor.

Modulo Results Across Common Scenarios

These rows cover the situations people most often check: an ordinary remainder, a divisor larger than the dividend, exact divisibility, parity tests, cyclic wrap-around, and decimal inputs.

a (dividend) b (divisor) a mod b What it means
17 5 2 Ordinary case: 5 fits into 17 three whole times, leaving 2 over.
5 17 5 Divisor larger than dividend: nothing can be removed, so the remainder is the dividend itself.
20 5 0 Exact divisibility: a remainder of 0 proves 5 is a factor of 20.
7 2 1 Odd/even check: mod 2 gives 1 for odd numbers and 0 for even ones.
26 26 0 Any nonzero number modulo itself is 0 — one full cycle lands back at the start.
15 12 3 12-hour clock wrap: 15:00 is displayed as 3 o'clock.
7.5 2.2 0.9 Decimals work too: 2.2 fits three times (6.6), leaving 0.9.

Worked example: the clock row

Substituting \(a = 15\) and \(b = 12\) into the floored definition:

$$r = 15 - 12 \cdot \left\lfloor \frac{15}{12} \right\rfloor = 15 - 12 \cdot \left\lfloor 1.25 \right\rfloor = 15 - 12 \cdot 1 = 3$$

Worked example: the decimal row

The same formula applies unchanged to non-integers:

$$r = 7.5 - 2.2 \cdot \left\lfloor \frac{7.5}{2.2} \right\rfloor = 7.5 - 2.2 \cdot \left\lfloor 3.4090\ldots \right\rfloor = 7.5 - 2.2 \cdot 3 = 7.5 - 6.6 = 0.9$$

Note that with binary floating-point arithmetic a computer may display this as 0.8999999999999995 rather than 0.9; when comparing decimal remainders in code, test against a small tolerance instead of exact equality.

Clock face illustrating modular arithmetic wrapping around 12
Modulo wraps numbers around a fixed range, like hours wrapping on a 12-hour clock.
Last updated:

Most popular in Math and Statistics

View all Math and Statistics calculators