Modulo Calculator

The modulo operation (often written as a mod b or a % b) returns the remainder after dividing a by b. For example, 17 mod 5 = 2 because 17 divided by 5 equals 3 with a remainder of 2. The modulo operation is fundamental in programming, cryptography, and number theory. It determines divisibility (if a mod b = 0, then b divides a evenly), cycles through repeating sequences, and forms the basis of modular arithmetic. Enter a dividend and divisor below to compute the remainder and quotient.

Quick Answer

17 mod 5 = 2, because 5 goes into 17 three times (5 x 3 = 15) with a remainder of 2.

Common Examples

Input Result
17 mod 5 2 (quotient: 3)
100 mod 7 2 (quotient: 14)
25 mod 5 0 (quotient: 5, divides evenly)
10 mod 3 1 (quotient: 3)
123 mod 10 3 (quotient: 12)

How It Works

The Formula

The modulo operation finds the remainder after integer division. Given a dividend a and a divisor b:

a mod b = a - b x floor(a / b)

Equivalently, the division algorithm states:

a = b x q + r

where q is the quotient (the integer part of a / b) and r is the remainder (the modulo result), with 0 <= r < b .

How Modulo Works

The modulo operation answers: “after dividing a by b as many whole times as possible, what is left over?” For example:

  • 17 mod 5: 5 fits into 17 three times (5 x 3 = 15), leaving 17 - 15 = 2.
  • 100 mod 7: 7 fits into 100 fourteen times (7 x 14 = 98), leaving 100 - 98 = 2.
  • 25 mod 5: 5 fits into 25 exactly five times (5 x 5 = 25), leaving 0.

When the remainder is 0, the divisor divides the dividend evenly. This is the basis for divisibility tests.

Modulo with Negative Numbers

For negative dividends, this calculator uses truncated division (the same behavior as the % operator in JavaScript, C, and Java). The quotient is truncated toward zero, and the remainder has the same sign as the dividend. For example, -17 mod 5 = -2 because the quotient is -3 (truncated from -3.4).

Worked Example

To compute 123 mod 10: divide 123 by 10 to get 12.3. The integer quotient is 12. Multiply back: 10 x 12 = 120. Subtract: 123 - 120 = 3. So 123 mod 10 = 3. Verification: 10 x 12 + 3 = 123.

To compute 100 mod 7: divide 100 by 7 to get 14.2857. The integer quotient is 14. Multiply back: 7 x 14 = 98. Subtract: 100 - 98 = 2. So 100 mod 7 = 2. Verification: 7 x 14 + 2 = 100.

Related Calculators

Frequently Asked Questions

What is the modulo operator in programming?
In most programming languages, the modulo operator is written as % (percent sign). For example, in JavaScript, Python, C, and Java, the expression 17 % 5 evaluates to 2. Python also provides divmod(a, b) which returns both the quotient and remainder as a tuple.
What is the difference between modulo and remainder?
For positive numbers, modulo and remainder are the same. The difference appears with negative numbers. The modulo operation (as in Python) always returns a non-negative result when the divisor is positive, while the remainder operation (as in C and JavaScript %) can return negative values. For example, -7 % 3 is -1 in JavaScript but 2 in Python.
How is modulo used in real applications?
Modulo is used extensively in programming and mathematics: determining if a number is even or odd (n % 2), cycling through array indices, implementing hash functions, converting between time units (seconds % 60 gives remaining seconds), cryptographic algorithms (RSA encryption uses modular exponentiation), and checking digit algorithms (ISBN, credit card validation).
What happens when the divisor is zero?
Division by zero is undefined in mathematics, so the modulo operation with a divisor of zero is also undefined. Most programming languages will throw an error or return NaN (Not a Number) in this case.
Can modulo be used with decimal numbers?
Yes. The modulo operation extends to decimal (floating-point) numbers. For example, 5.5 mod 2 = 1.5 because 2 fits into 5.5 twice (2 x 2 = 4) with 1.5 remaining. However, floating-point modulo can produce small rounding artifacts due to how computers represent decimals.