Report

Help us improve this tool

Modulo Calculator

Calculate the modulo (remainder) of a divided by b with step-by-step solutions showing division, remainder, and verification

O M T

What is a Modulo Calculator?

A Modulo Calculator computes the remainder when one number (the dividend) is divided by another (the divisor). In mathematical notation, this is written as a mod b = r, where a is the dividend, b is the modulus (divisor), and r is the remainder. The modulo operation is fundamental in modular arithmetic, a branch of number theory with applications in computer science, cryptography, and everyday calculations. For related math tools, check the Multiples Calculator, Number Sequence Calculator, and Scientific Calculator.

How to Calculate Modulo

To calculate a mod b manually:

  1. Divide a by b to find the quotient: q = floor(a / b)
  2. Multiply the quotient by the divisor: q × b
  3. Subtract that product from the dividend: r = a - (q × b)
  4. The result r is the remainder, also known as a mod b

For example, to find 17 mod 5: Divide 17 by 5 to get quotient 3. Multiply 3 × 5 = 15. Subtract 15 from 17, giving remainder 2. So 17 mod 5 = 2.

Understanding the Modulo Operation

The modulo operation (often abbreviated as "mod") finds the remainder after division of one number by another. For positive numbers, this is straightforward: if you divide 20 by 6, 6 goes into 20 three times (18) with 2 left over, so 20 mod 6 = 2.

When the divisor is larger than the dividend, the remainder is simply the dividend itself. For example, 3 mod 10 = 3 because 10 does not divide into 3 at all.

Modulo vs. Remainder

While often used interchangeably, modulo and remainder operations can differ for negative numbers. The modulo operation in modular arithmetic always returns a result in the range [0, b-1] for positive b, while some programming languages implement remainder operations that can return negative results. This calculator uses the mathematical modulo definition: a mod b = a - (b × floor(a / b)).

Applications of the Modulo Operation

The modulo operation appears in many practical scenarios:

  • Time arithmetic: 23 hours after 10 AM is (10 + 23) mod 12 = 9 (9 AM the next day)
  • Even/odd detection: A number is even if n mod 2 = 0, odd if n mod 2 = 1
  • Cyclic patterns: Determining the day of the week for a given date
  • Cryptography: RSA encryption relies heavily on modular arithmetic
  • Computer science: Hash functions, array indexing, and checksums
  • Divisibility checks: A number is divisible by another if a mod b = 0

If you're working with percentages or fractions, also try the Percentage Calculator, Rounding Methods Calculator, and Significant Figures Calculator.

Common Modulo Examples

Expression Calculation Result
10 mod 3 10 ÷ 3 = 3 R 1 1
25 mod 7 25 ÷ 7 = 3 R 4 4
100 mod 99 100 ÷ 99 = 1 R 1 1
7 mod 10 7 ÷ 10 = 0 R 7 7
0 mod 5 0 ÷ 5 = 0 R 0 0

Key Properties of Modulo

  • Identity: a mod a = 0 for any non-zero a
  • Zero: 0 mod b = 0 for any non-zero b
  • Distribution: (a + b) mod m = ((a mod m) + (b mod m)) mod m
  • Multiplication: (a × b) mod m = ((a mod m) × (b mod m)) mod m
  • Range: For positive divisor b, the result is always in [0, b-1]

Frequently Asked Questions

What does a mod b mean?

The expression a mod b means "a modulo b" and represents the remainder when a is divided by b. For example, 17 mod 5 = 2 because when 17 is divided by 5, the quotient is 3 and the remainder is 2.

How is modulo different from regular division?

Regular division gives you the quotient (how many times b fits into a), while modulo gives you the remainder (what is left over). For example, 20 ÷ 6 = 3.333 or 3 R 2, but 20 mod 6 = 2. Both operations are related: a = (b × quotient) + remainder.

Can the divisor b be zero in a modulo calculation?

No. Division by zero is undefined in mathematics, and the same applies to the modulo operation. The divisor b must always be a non-zero number. If you attempt to calculate a mod 0, there is no valid mathematical result.

What is the result when the dividend is smaller than the divisor?

When the dividend a is smaller than the divisor b, the remainder is simply a. For example, 3 mod 10 = 3 because 10 cannot divide into 3 at all (the quotient is 0 and the remainder is 3).

How is modulo used in programming?

In programming, the modulo operator (often written as % in languages like JavaScript, Python, and C++) is used for: checking if a number is even or odd (n % 2), wrapping around array indices, generating cyclic patterns, implementing hash functions, and converting between units of time. Many languages implement the modulo as the remainder operator, which may behave differently for negative numbers.

What are some real-world uses of modular arithmetic?

Modular arithmetic appears in: clock arithmetic (12-hour and 24-hour time systems), calendar calculations (days of the week), ISBN and credit card check digits, RSA encryption, cyclic redundancy checks (CRC) in data transmission, and creating repeating patterns in computer graphics and music theory.

What is the difference between mod and remainder?

For positive numbers, mod and remainder produce the same result. For negative numbers, they can differ. The mathematical modulo operation (a mod b) always returns a non-negative result when b is positive, while the remainder operation in some programming languages may return a negative result. For example, in mathematical modulo: -7 mod 3 = 2, but in some languages: -7 % 3 = -1 (remainder).