Perform modular arithmetic operations with step-by-step solutions
Enter integers and select an operation to perform modular arithmetic
Congruence
a ≡ b mod m means m divides (a - b)
Modular Inverse
a × a⁻¹ ≡ 1 mod m
Exists only if gcd(a, m) = 1
a ≡ b mod m
Where: a and b are integers, m is the modulus (positive integer)
Our Modular Arithmetic Calculator helps you perform various modular arithmetic operations including addition, subtraction, multiplication, division, and finding modular inverses with step-by-step solutions. Modular arithmetic is fundamental in number theory, cryptography, and computer science.
Modular arithmetic is a system of arithmetic for integers where numbers "wrap around" upon reaching a certain value called the modulus. Instead of continuing indefinitely, numbers reset to zero when they reach the modulus value.
For example, in modulo 7 arithmetic: 8 ≡ 1 mod 7, because 8 - 1 = 7, which is divisible by 7.
Add two numbers and take the remainder when divided by m.
Subtract b from a and take the remainder. If negative, add m to make it positive.
Multiply two numbers and take the remainder when divided by m.
Division is multiplication by the modular inverse. Requires that b and m are coprime.
The modular inverse exists only if gcd(a, m) = 1. Calculated using the Extended Euclidean Algorithm.
Example 1: Modular Addition
Calculate (5 + 3) mod 7
5 + 3 = 8
8 mod 7 = 1
Result: 1
Example 2: Modular Inverse
Find modular inverse of 3 modulo 7
Using Extended Euclidean Algorithm
Inverse: 5 (since 3 × 5 = 15 ≡ 1 mod 7)
Example 3: Modular Division
Calculate (4 × 3⁻¹) mod 7
First find inverse of 3 mod 7 = 5
4 × 5 = 20
20 mod 7 = 6
Result: 6
Q1. What does "modulo" mean?
A: Modulo operation finds the remainder when one number is divided by another. For example, 17 mod 5 = 2, because 17 ÷ 5 = 3 with remainder 2.
Q2. When does a modular inverse exist?
A: A modular inverse exists only when the number and modulus are coprime, meaning their greatest common divisor is 1.
Q3. How is modular arithmetic used in cryptography?
A: Modular arithmetic forms the basis of many cryptographic algorithms, including RSA, where large prime numbers and modular exponentiation ensure secure communication.
Q4. What is the Extended Euclidean Algorithm?
A: It's an extension of Euclid's algorithm for finding GCD that also finds integers x and y such that ax + by = gcd(a,b), which is used to find modular inverses.
Q5. Can negative numbers be used in modular arithmetic?
A: Yes, but results are usually normalized to be between 0 and m-1. For example, -3 mod 7 = 4, since -3 + 7 = 4.
For further understanding and validation of the formulas used above, we recommend exploring these authoritative resources: