Modular Arithmetic Calculator

Perform calculations with modular arithmetic and solve congruences

Result
2
17 + 5 ≡ 22 ≡ 10 mod 12
Modulus
12
Current modulus
Operation
Addition
Current operation
Equivalent
10
Smallest positive
Calculation Steps
1 17 + 5 = 22
2 22 mod 12 = 22 - 12 × 1 = 10
3 Result: 10
What is Modular Arithmetic?

Modular arithmetic is a system of arithmetic for integers, where numbers "wrap around" upon reaching a certain value—the modulus. It is often called "clock arithmetic" because of its circular nature, similar to how hours wrap around on a clock.

  • Modular arithmetic is fundamental in number theory
  • Used in cryptography algorithms like RSA
  • Essential for computer science and coding theory
  • Helps solve problems in combinatorics and algebra
  • Used in music theory and calendar calculations
Modular Arithmetic Properties
If a ≡ b mod m and c ≡ d mod m, then:

a + c ≡ b + d mod m
a - c ≡ b - d mod m
a × c ≡ b × d mod m
a^k ≡ b^k mod m for any positive integer k
Modular Clock Visualization

Frequently Asked Questions

Modular arithmetic is a system of arithmetic for integers where numbers "wrap around" after reaching a certain value called the modulus. Two integers a and b are congruent modulo n if their difference is divisible by n. This is written as a ≡ b mod n.

For example:
  • 15 ≡ 3 mod 12 (because 15 - 3 = 12, divisible by 12)
  • 22 ≡ 10 mod 12 (because 22 - 10 = 12, divisible by 12)
  • 7 ≡ 1 mod 3 (because 7 - 1 = 6, divisible by 3)
This system is similar to clock arithmetic, where after 12 comes 1 again.

To calculate a mod n (the remainder when a is divided by n):
  1. Divide a by n
  2. Take the integer part of the quotient
  3. Multiply that integer by n
  4. Subtract that result from a
The result is the remainder, which is always between 0 and n-1.

Example: Calculate 17 mod 5
  1. 17 ÷ 5 = 3.4 → integer part is 3
  2. 3 × 5 = 15
  3. 17 - 15 = 2
  4. So 17 ≡ 2 mod 5
Alternatively, you can use the formula:
a mod n = a - n × floor(a/n)

The modular inverse of a number a modulo n is a number b such that:

a × b ≡ 1 mod n

The modular inverse exists only if a and n are coprime (gcd(a, n) = 1).

Example: Find the inverse of 3 modulo 11
We need to find b such that 3b ≡ 1 mod 11
Trying values: 3×1=3, 3×2=6, 3×3=9, 3×4=12≡1 mod 11
So b=4 is the inverse of 3 mod 11

Modular inverses are crucial in cryptography and for solving linear congruences.

Modular arithmetic is fundamental to modern cryptography:
  • RSA Encryption: Based on modular exponentiation and the difficulty of factoring large numbers
  • Diffie-Hellman Key Exchange: Uses modular exponentiation to securely exchange keys
  • Elliptic Curve Cryptography: Relies on modular arithmetic over finite fields
  • Hash Functions: Many cryptographic hash functions use modular operations
  • Digital Signatures: Algorithms like DSA use modular arithmetic
The security of these systems often depends on the difficulty of solving problems like:
  • Discrete logarithm problem: Finding x in a^x ≡ b mod p
  • Integer factorization: Factoring large composite numbers
Modular arithmetic provides the mathematical foundation for these secure systems.

Modular arithmetic has numerous practical applications:
  • Timekeeping: 12-hour and 24-hour clocks use modulo 12 and modulo 24
  • Calendars: Calculating days of the week (modulo 7)
  • ISBN Numbers: Check digits use modulo 11
  • Computer Science: Hashing algorithms, circular buffers, checksums
  • Music Theory: Octave equivalence in pitch classes (modulo 12)
  • Finance: Calculating interest and amortization schedules
  • Game Theory: Cyclic games and strategies
  • Barcodes: Error detection with modular arithmetic
Its ability to handle cyclical patterns makes it useful in many fields.