Skip to main content

Modulo Calculator

Calculate the remainder after division

Category: Mathematics

Modulo Calculator Inputs

Enter values to calculate

Enter the Dividend value used by the Modulo Calculator.

Enter the Divisor value used by the Modulo Calculator.

Enable JavaScript for interactive calculation and step-by-step results.

Modulo Calculator Formula

Equation

a \bmod b = r

Excel Formula

=ab=r

Variables

  • Dividend — Enter the Dividend value used by the Modulo Calculator.
  • Divisor — Enter the Divisor value used by the Modulo Calculator.

How the Modulo Calculator Works

The modulo operation, also known as the remainder operation, finds the remainder after division of one number by another. Mathematically expressed as $a \bmod b = r$, it returns the remainder $r$ when dividend $a$ is divided by divisor $b$. This fundamental operation is essential in number theory, abstract algebra, cryptography, computer science, and discrete mathematics. The modulo operation creates equivalence classes that partition integers into congruence classes, forming the mathematical foundation for modular arithmetic systems used in cyclic structures like clocks, calendars, and cryptographic algorithms.

The core relationship is a \bmod b = r. Typical inputs include Dividend, Divisor.

Enter your values in the modulo calculator above, review the step-by-step solution, and compare against the worked examples below so you can see how each input changes the result. This free online mathematics tool is built for homework, design checks, and professional verification.

Modulo Calculator Theory & Explanation

Mathematical Definition and Division Algorithm

The modulo operation is formally defined through the division algorithm: for any integers a (dividend) and b (divisor) where b ≠ 0, there exist unique integers q (quotient) and r (remainder) such that a = bq + r with 0 ≤ r < |b|. The modulo operation returns this remainder r. For example, 17 = 5 × 3 + 2, so 17 \bmod 5 = 2. The quotient q = \lfloor a/b \rfloor represents how many complete groups of b fit into a, while the remainder represents what's left over. This relationship is fundamental to understanding divisibility, factors, and number theory.

a = bq + r, \quad 0 ≤ r < |b|, \quad r = a \bmod b \quad \textwhere \quad q = \lfloor a/b \rfloor

Congruence Relation and Equivalence Classes

Two integers a and c are said to be congruent modulo b (written a \equiv c ±odb) if they have the same remainder when divided by b, or equivalently, if b divides (a - c). This creates equivalence classes that partition all integers into b distinct classes: [0], [1], [2], \ldots, [b-1]. For example, with modulo 5, the equivalence class [2] contains \\ldots, -8, -3, 2, 7, 12, 17, \ldots\ - all numbers that leave remainder 2 when divided by 5. This concept forms the foundation of modular arithmetic and abstract algebra.

a \equiv c ±odb \iff b \mid (a - c) \iff a \bmod b = c \bmod b

Properties and Algebraic Structure

Modulo arithmetic preserves many algebraic properties. Addition property: (a + b) \bmod m = ((a \bmod m) + (b \bmod m)) \bmod m. Multiplication property: (a × b) \bmod m = ((a \bmod m) × (b \bmod m)) \bmod m. Subtraction property: (a - b) \bmod m = ((a \bmod m) - (b \bmod m) + m) \bmod m. These properties allow us to perform modular reduction at any stage of computation, which is crucial for handling large numbers in cryptography. Additionally, modulo operation is distributive over addition and multiplication but not over division.

\beginalign*(a + b) \bmod m &= ((a \bmod m) + (b \bmod m)) \bmod m \\ (a × b) \bmod m &= ((a \bmod m) × (b \bmod m)) \bmod m \\ (a - b) \bmod m &= ((a \bmod m) - (b \bmod m) + m) \bmod m\endalign*

Negative Numbers and Implementation Differences

Handling negative dividends in modulo operations varies by convention. The mathematical definition ensures 0 ≤ r < |b|, always giving a non-negative remainder. For example, -17 \bmod 5 should mathematically equal 3 because -17 = 5 × (-4) + 3. However, many programming languages implement the remainder operation differently: C, Java, and JavaScript may return negative remainders (e.g., -17 \% 5 = -2), while Python follows the mathematical convention (-17 \% 5 = 3). To convert between conventions: \textmath\_mod(a, b) = ((a \% b) + b) \% b ensures a non-negative result.

-17 \bmod 5 = 3 \quad \textbecause \quad -17 = 5 × (-4) + 3, \quad 0 ≤ 3 < 5

Geometric and Visual Interpretation

Geometrically, modulo operation represents cyclic or circular arithmetic. Imagine a number line wrapped into a circle with circumference b. Starting at 0 and moving a units along this circle gives you the position a \bmod b. This explains clock arithmetic: 15 hours on a 12-hour clock is 3 o'clock because 15 \bmod 12 = 3. The visualization also applies to periodic phenomena: days of the week, musical octaves, color wheels, and angular measurements all use modular arithmetic naturally. The "wrapping around" behavior creates cycles where values repeat with period b.

\textPosition on circular number line = (a \bmod b), \quad \textperiod = b

Applications in Computer Science

Modulo operations are ubiquitous in programming and computer science. **Hash Functions**: Computing array indices with \texthash(key) \bmod \texttableSize distributes data across hash tables. **Circular Buffers**: Ring buffers use (\textindex + 1) \bmod \textsize to wrap around efficiently. **Random Number Generation**: Linear congruential generators use x_n+1 = (ax_n + c) \bmod m. **Checksums**: Error detection algorithms like Luhn algorithm use modulo 10. **Bitwise Operations**: Testing even/odd with n \bmod 2, extracting specific bits, and implementing circular shifts all rely on modular arithmetic.

\textHash Index = h(k) \bmod m, \quad \textLCG: x_n+1 = (ax_n + c) \bmod m

Applications in Cryptography

Modular arithmetic forms the mathematical backbone of modern cryptography. **RSA Encryption**: Uses modular exponentiation c = m^e \bmod n for encryption and m = c^d \bmod n for decryption, where security depends on the difficulty of factoring large moduli. **Diffie-Hellman Key Exchange**: Computes shared secrets using g^ab \bmod p without transmitting private keys. **Elliptic Curve Cryptography**: Performs point operations in finite fields defined by modular arithmetic. **Digital Signatures**: DSA and ECDSA use modular inverse and modular multiplication to create unforgeable signatures. The discrete logarithm problem in modular arithmetic provides computational hardness for these systems.

\textRSA: c \equiv m^e ±odn, \quad m \equiv c^d ±odn, \quad \textwhere ed \equiv 1 ±od\phi(n)

Applications in Number Theory

Modulo operation is central to many number-theoretic concepts. **Divisibility Tests**: A number n is divisible by d if and only if n \bmod d = 0. **Prime Testing**: Fermat's Little Theorem states that if p is prime, then a^p-1 \equiv 1 ±odp for any a not divisible by p, forming the basis for probabilistic primality tests. **Chinese Remainder Theorem**: Solves systems of congruences x \equiv a_i ±odm_i when moduli are coprime. **Euler's Theorem**: Generalizes Fermat's theorem: a^\phi(n) \equiv 1 ±odn when \gcd(a,n) = 1, where \phi is Euler's totient function.

\textFermat: a^p-1 \equiv 1 ±odp, \quad \textEuler: a^\phi(n) \equiv 1 ±odn

Modular Inverse and Division

While division doesn't work directly in modular arithmetic, we can multiply by the modular inverse. The modular multiplicative inverse of a modulo m is an integer x such that ax \equiv 1 ±odm, written a^-1 \bmod m. This inverse exists if and only if \gcd(a, m) = 1 (i.e., a and m are coprime). The Extended Euclidean Algorithm efficiently computes modular inverses. For example, 3 × 5 \equiv 1 ±od7, so 3^-1 \equiv 5 ±od7. This enables "division" in modular arithmetic: dividing by a means multiplying by a^-1.

a · a^-1 \equiv 1 ±odm \quad \textexists iff \quad \gcd(a, m) = 1

Practical Examples and Real-World Uses

Modulo appears in countless everyday applications. **Calendar Calculations**: Determining day of the week uses modulo 7; finding the day 100 days from Tuesday: (2 + 100) \bmod 7 = 4 (Friday). **Music Theory**: Notes repeat in octaves; note frequency 1000 Hz is the same pitch as 500 Hz and 2000 Hz (modulo an octave). **ISBN/Credit Card Validation**: Check digits use modulo 10 or 11 for error detection. **Sports Scheduling**: Round-robin tournaments use modular arithmetic to ensure fair pairings. **Time Zones**: Converting between time zones involves modulo 24 arithmetic. **Angle Normalization**: Converting angles to [0°, 360°) or [-180°, 180°) ranges.

\textDay of week after n \text days: (\textcurrent\_day + n) \bmod 7

Modulo Calculator Worked Examples

Worked Example

Inputs

  • dividend: 17
  • divisor: 5

Result: 2

Explanation

17 ÷ 5 = 3 with remainder 2, so 17 mod 5 = 2. This means 17 = 5 × 3 + 2.

Clock Arithmetic

Inputs

  • dividend: 15
  • divisor: 12

Result: 3

Explanation

On a 12-hour clock, 15 hours is 3 o'clock because 15 \bmod 12 = 3. This demonstrates how modulo creates cyclic behavior.

Common Modulo Calculator Use Cases

  • Homework and exam practice
  • Engineering and science coursework
  • Quick verification of hand calculations
  • Modulo homework and study
  • Modulo design and analysis

Modulo Calculator FAQs

What is the result of any number modulo 0?

Division by zero is undefined in mathematics, so any number modulo 0 is also undefined. The divisor must be non-zero for the modulo operation to be valid. This is similar to how you cannot divide by zero - it would require an infinite number of groups, which is not meaningful mathematically.

Can the result of modulo be negative?

In the standard mathematical definition, the remainder (and thus modulo result) is always non-negative and strictly less than the absolute value of the divisor: 0 ≤ r < |b|. However, some programming languages like C, Java, and JavaScript implement the remainder operator (%) differently and may return negative values for negative dividends. Python follows the mathematical convention, always returning non-negative remainders. To convert a potentially negative remainder to the mathematical modulo: ((a \% b) + b) \% b.

How do you find modulo of a negative number?

For negative numbers using the mathematical definition, apply the formula: a \bmod b = a - b × \lfloor a/b \rfloor. For example, -17 \bmod 5 = -17 - 5 × \lfloor -17/5 \rfloor = -17 - 5 × (-4) = -17 + 20 = 3. The key is that the floor function \lfloor -17/5 \rfloor = -4 (not -3), ensuring the remainder falls in the range [0, 5). This maintains the cyclic property of modular arithmetic.

What is the relationship between modulo and division?

Modulo and division are intimately related through the division algorithm. If a ÷ b = q with remainder r, then a = bq + r where q is the quotient (q = \lfloor a/b \rfloor) and r is the remainder (r = a \bmod b). The division gives you how many complete groups fit (quotient), while modulo gives you what's left over (remainder). Together, they completely describe the relationship between dividend and divisor. For example: 17 ÷ 5 = 3 remainder 2 means 17 = 5 × 3 + 2, so 17 \bmod 5 = 2.

Why is modulo important in cryptography?

Modular arithmetic is fundamental to modern cryptography because it creates finite fields with special properties. RSA encryption relies on modular exponentiation being easy to compute but hard to reverse (the discrete logarithm problem). The security of RSA depends on the difficulty of factoring large numbers - knowing n = pq (a product of two large primes) and c = m^e \bmod n doesn't easily reveal m. Modulo operations also enable Diffie-Hellman key exchange, elliptic curve cryptography, and digital signatures. The mathematical properties of modular arithmetic (commutativity, associativity, distributivity) allow complex operations while keeping numbers bounded.

How is modulo used in hash functions?

Hash functions use modulo to map large input spaces to smaller fixed-size ranges. A typical pattern is \textindex = \texthash(\textkey) \bmod \texttableSize, distributing data evenly across an array. For example, with a hash table of size 10, the key "apple" might hash to 12345, and 12345 \bmod 10 = 5 gives the bucket index. The modulo operation ensures all hash values fit within valid array indices [0, \textsize-1]. Using prime numbers for table sizes often improves distribution quality and reduces collisions.

What are equivalence classes in modular arithmetic?

Equivalence classes partition all integers into groups where members are congruent modulo n. For modulo 5, there are 5 classes: [0] = \\ldots, -10, -5, 0, 5, 10, \ldots\, [1] = \\ldots, -9, -4, 1, 6, 11, \ldots\, etc. Two numbers are in the same class if they have the same remainder: a \equiv b ±odn means a \bmod n = b \bmod n. This concept is fundamental to abstract algebra and allows us to perform arithmetic on classes rather than individual numbers, forming structures like \mathbbZ/n\mathbbZ (integers modulo n).

Can you divide in modular arithmetic?

Division doesn't work directly in modular arithmetic, but multiplication by the modular inverse achieves the same result. To divide by a modulo m, multiply by a^-1 (the modular inverse), which satisfies a · a^-1 \equiv 1 ±odm. However, a^-1 only exists if \gcd(a, m) = 1 (i.e., a and m are coprime). For example, to compute 7 ÷ 3 ±od11: first find 3^-1 \bmod 11 = 4 (since 3 × 4 = 12 \equiv 1 ±od11), then calculate 7 × 4 = 28 \equiv 6 ±od11. The Extended Euclidean Algorithm efficiently computes modular inverses.

How do you test if a number is divisible by 3 using modulo?

A number is divisible by 3 if and only if n \bmod 3 = 0. Interestingly, a number is divisible by 3 exactly when the sum of its digits is divisible by 3. For example, 12345 \bmod 3 = 0 because 1+2+3+4+5 = 15, and 15 \bmod 3 = 0. This works because 10 \equiv 1 ±od3, so each digit contributes its face value to the remainder. Similar rules exist for other divisors: for 9, sum the digits; for 11, compute alternating sum of digits. These divisibility rules are applications of modular arithmetic properties.

What is the difference between mod and % in programming?

The mathematical modulo operation and programming remainder operators (%) differ in handling negative numbers. Mathematical modulo always returns non-negative results in [0, |b|), while many programming languages' % operator can return negative values. In Python: -17 \% 5 = 3 (follows mathematical convention). In JavaScript/C/Java: -17 \% 5 = -2 (remainder has same sign as dividend). To convert programming remainder to mathematical modulo: \textmod(a, b) = ((a \% b) + b) \% b. This difference matters in algorithms using cyclic indexing, where negative indices should wrap around to the end.