Modular Arithmetic

(a op b) mod m operations

Calculates (a op b) mod m

About This Calculator

Modular arithmetic, sometimes called clock arithmetic, studies remainders after division. It is fundamental to computer science, cryptography (RSA encryption relies on it), hashing algorithms, and cyclic processes like days of the week.

Formula

(a + b) mod m = ((a mod m) + (b mod m)) mod m
(a x b) mod m = ((a mod m) x (b mod m)) mod m
Modular inverse: a^-1 mod m where a x a^-1 ≡ 1 (mod m)

Example Calculation

Compute (17 + 25) mod 7 and (17 x 25) mod 7

  1. (17 + 25) mod 7 = 42 mod 7 = 0
  2. 17 mod 7 = 3, 25 mod 7 = 4
  3. (3 + 4) mod 7 = 7 mod 7 = 0 (confirmed); (3 x 4) mod 7 = 12 mod 7 = 5
(17+25) mod 7 = 0; (17x25) mod 7 = 5

Addition mod 7 (partial table)

+ mod 70123
00123
11234
22345
33456
44560
55601
66012

Frequently Asked Questions

What does a ≡ b (mod m) mean?
It means a and b leave the same remainder when divided by m, or equivalently that m divides (a - b). For example, 17 ≡ 3 (mod 7) because 17 - 3 = 14 is divisible by 7.
How is modular arithmetic used in cryptography?
RSA encryption relies on the fact that computing a^b mod n is easy, but reversing it (finding a from the result) is computationally infeasible for large n. This asymmetry secures internet communications.
What is a modular inverse?
The modular inverse of a (mod m) is a number x such that a*x ≡ 1 (mod m). It exists only when GCD(a, m) = 1. For example, the inverse of 3 mod 7 is 5, because 3*5 = 15 ≡ 1 (mod 7).