Modulo Calculator

Calculate the modulo (remainder) of a division operation.

Enter Values

mod

Expression

17 mod 5 = 2

Remainder (Modulo)

2

17 mod 5 = 2

Division Details

Quotient (integer)3
Floor Quotient3
Exact Division3.400000
JavaScript Modulo (%)2
Mathematical Modulo2

Verification

dividend = quotient * divisor + remainder

17 = 3 * 5 + 2

17 = 17 (correct)

Modulo Operation

Definition

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

The modulo operation finds the remainder after division.

Properties

0 ≤ a mod b < |b| (for mathematical modulo)

(a + b) mod n = ((a mod n) + (b mod n)) mod n

(a * b) mod n = ((a mod n) * (b mod n)) mod n

What is the Modulo Operation?

The modulo operation (also called modulus or mod) finds the remainder after dividing one number by another. It's a fundamental operation in mathematics and computer science, used in everything from cryptography to everyday calculations like determining what day of the week it will be.

Definition:

  • a mod n = the remainder when a is divided by n
  • Notation: a mod n, a % n (programming), or a (mod n)
  • Result is always between 0 and n-1 (for positive n)

Simple Examples:

Operation Division Result Explanation
17 mod 5 17 = 5×3 + 2 2 Remainder after dividing 17 by 5
24 mod 6 24 = 6×4 + 0 0 24 is divisible by 6
7 mod 10 7 = 10×0 + 7 7 7 < 10, so remainder is 7
100 mod 7 100 = 7×14 + 2 2 14 sevens fit, 2 left over

Modulo Formula and Definition

The modulo operation can be defined mathematically:

Modulo Definition

a mod n = a - n × ⌊a/n⌋ Where: • ⌊x⌋ is the floor function (round down) • a is the dividend • n is the divisor (modulus) Alternatively: a = n × q + r where q = quotient, r = remainder (a mod n) and 0 ≤ r < n Example: 23 mod 7 23 = 7 × ⌊23/7⌋ + r 23 = 7 × 3 + 2 So 23 mod 7 = 2

Where:

  • a= Dividend (number being divided)
  • n= Divisor (modulus)
  • ⌊x⌋= Floor function - greatest integer ≤ x
  • q= Quotient (integer result of division)
  • r= Remainder (mod result)

Properties of Modular Arithmetic

Modular arithmetic follows specific rules that make calculations easier:

Modular Arithmetic Properties

Addition: (a + b) mod n = ((a mod n) + (b mod n)) mod n Subtraction: (a - b) mod n = ((a mod n) - (b mod n) + n) mod n Multiplication: (a × b) mod n = ((a mod n) × (b mod n)) mod n Power: a^k mod n = (a mod n)^k mod n Examples: (17 + 8) mod 5 = (2 + 3) mod 5 = 5 mod 5 = 0 (17 × 8) mod 5 = (2 × 3) mod 5 = 6 mod 5 = 1

Where:

  • a, b= Any integers
  • n= The modulus
  • mod= Modulo operation

Negative Numbers and Modulo

Handling negative numbers in modulo varies by definition:

Definition -7 mod 3 Used In
Truncated Division -1 C, C++, Java, JavaScript
Floored Division 2 Python, Ruby, Mathematics
Euclidean 2 Mathematical definition

To always get a positive result:

((a mod n) + n) mod n works in any language

Example: -7 mod 3

  • Truncated: -7 = 3 × (-2) + (-1), so result is -1
  • Floored: -7 = 3 × (-3) + 2, so result is 2

How to Use This Calculator

Our modulo calculator handles various operations:

  1. Enter Dividend: The number being divided (a)
  2. Enter Divisor: The modulus (n)
  3. Click Calculate: Get the remainder
  4. View Results:
    • Remainder (mod result)
    • Quotient (integer division)
    • Full equation: a = n × q + r
    • Both truncated and floored results

Additional Features:

  • Modular arithmetic calculator
  • Modular exponentiation (a^b mod n)
  • Modular inverse finder
  • Congruence checker

Input Types:

  • Positive integers: 17 mod 5
  • Negative integers: -7 mod 3
  • Large numbers: 123456789 mod 97

Applications of Modulo

Modulo is essential in many practical applications:

Time and Calendars:

  • Clock arithmetic: (hour + x) mod 12 or mod 24
  • Day of week: (today + days) mod 7
  • Leap years: year mod 4 = 0 (simplified)

Computer Science:

  • Hash functions: index = hash mod table_size
  • Circular buffers: pos = (pos + 1) mod size
  • Random numbers: Many generators use modulo
  • Array indexing: Wrap-around behavior

Cryptography:

  • RSA encryption: c = m^e mod n
  • Diffie-Hellman: Key exchange
  • Hash functions: MD5, SHA use modular arithmetic
  • Checksums: ISBN, credit card validation

Everyday Uses:

  • Even/odd check: n mod 2 (0 = even, 1 = odd)
  • Digit extraction: n mod 10 gets last digit
  • Divisibility: a mod b = 0 means b divides a
  • Cycling through options: next = (current + 1) mod total

Modular Multiplicative Inverse

The modular inverse of a (mod n) is a number b such that (a × b) mod n = 1:

Modular Inverse

a × a⁻¹ ≡ 1 (mod n) Exists if and only if GCD(a, n) = 1 Finding Methods: 1. Extended Euclidean Algorithm 2. Fermat's Little Theorem (when n is prime): a⁻¹ ≡ a^(n-2) (mod n) Example: 3⁻¹ mod 7 3 × ? ≡ 1 (mod 7) 3 × 5 = 15 = 7×2 + 1 ≡ 1 (mod 7) So 3⁻¹ ≡ 5 (mod 7)

Where:

  • a⁻¹= Modular inverse of a
  • = Congruent (equal under mod)
  • GCD= Greatest Common Divisor

Worked Examples

Basic Modulo Calculation

Problem:

Calculate 47 mod 8

Solution Steps:

  1. 1Divide 47 by 8: 47 ÷ 8 = 5.875
  2. 2Integer part (quotient) = 5
  3. 3Quotient × divisor = 5 × 8 = 40
  4. 4Remainder = 47 - 40 = 7
  5. 5Verify: 8 × 5 + 7 = 40 + 7 = 47 ✓

Result:

47 mod 8 = 7

Clock Arithmetic

Problem:

It's 10 AM. What time will it be in 27 hours?

Solution Steps:

  1. 1Current hour: 10
  2. 2Add hours: 10 + 27 = 37
  3. 3Apply mod 24: 37 mod 24
  4. 437 = 24 × 1 + 13
  5. 5Result: 13 (1 PM on a 24-hour clock)
  6. 6Or: (37 mod 12) = 1 (1 o'clock on 12-hour)

Result:

1 PM (13:00)

Day of Week Calculation

Problem:

Today is Tuesday (day 2). What day will it be in 100 days?

Solution Steps:

  1. 1Number the days: Sun=0, Mon=1, Tue=2, ..., Sat=6
  2. 2Today = 2 (Tuesday)
  3. 3Add days: 2 + 100 = 102
  4. 4Apply mod 7: 102 mod 7
  5. 5102 = 7 × 14 + 4
  6. 6Result: 4 = Thursday

Result:

Thursday

Tips & Best Practices

  • a mod n is always between 0 and n-1 (for positive n in most definitions)
  • If a < n, then a mod n = a (nothing to divide)
  • a mod n = 0 means n divides a evenly (a is divisible by n)
  • n mod 2 is 0 for even numbers, 1 for odd numbers
  • n mod 10 gives the last digit of n
  • For negative numbers: ((a mod n) + n) mod n always gives positive result
  • Modular arithmetic preserves operations: (a + b) mod n = ((a mod n) + (b mod n)) mod n

Frequently Asked Questions

Different programming languages use different definitions for the division operation that defines modulo. Languages like C, Java, and JavaScript use 'truncated division' (round toward zero), giving -7 % 3 = -1. Python uses 'floored division' (round down), giving -7 % 3 = 2. Both are mathematically valid, just different conventions. The floored version always gives positive results for positive divisors.
For positive numbers, they're identical. For negative numbers, 'mod' (mathematical modulo) typically gives a result with the same sign as the divisor, while 'rem' (remainder) gives a result with the same sign as the dividend. In math: -7 mod 3 = 2. In programming (rem): -7 rem 3 = -1. Python's % is true mod; C's % is rem.
Modular arithmetic is 'one-way' - easy to compute but hard to reverse. If you know a, b, and n, computing a^b mod n is fast. But given only the result and n, finding a and b is extremely hard (the discrete logarithm problem). This asymmetry is the foundation of RSA, Diffie-Hellman, and many other cryptographic systems.
Use modulo: a is divisible by b if a mod b = 0. For example: 24 mod 6 = 0, so 24 is divisible by 6. 25 mod 6 = 1, so 25 is not divisible by 6. This is useful for checking even/odd (n mod 2), divisibility by 3, 5, 9, etc.
Modular exponentiation calculates a^b mod n efficiently. Instead of computing a^b (which could be astronomically large) then taking mod, we use repeated squaring with mod at each step. This keeps numbers manageable. For example, 7^100 mod 13 can be computed quickly without ever calculating 7^100 directly. This is essential for RSA encryption.
Mathematically, yes, but it's rarely used and behavior varies by language. Most practical applications use positive moduli. If needed, |n| is typically used. The important thing is that the result's range depends on the definition: truncated gives results between -(|n|-1) and |n|-1, floored keeps the sign of n.

Sources & References

Last updated: 2026-01-22