TFT

Modular Arithmetic Calculator – Compute mod n Operations

Perform modular arithmetic operations including addition, subtraction, multiplication, and exponentiation under any modulus with our free online calculator. Essential for cryptography and number theory.

Examples:

Understanding Modular Arithmetic

Modular arithmetic is "clock math" – arithmetic that wraps around after reaching a certain value called the modulus. Just like a 12-hour clock wraps from 12 back to 1, modular arithmetic wraps numbers back to 0 after reaching the modulus.

We write "a mod m" or "a (mod m)" to mean the remainder when a is divided by m. For example, 17 mod 5 = 2 because 17 = 3 x 5 + 2. This simple concept powers modern cryptography, computer science, and number theory.

Modular Operations

Addition & Subtraction

(a + b) mod m = ((a mod m) + (b mod m)) mod m

Reduce first, then operate, then reduce again

Multiplication

(a x b) mod m = ((a mod m) x (b mod m)) mod m

Same pattern as addition

Modular Exponentiation

For a^b mod m, use repeated squaring to avoid huge intermediate numbers:

a^b mod m = ((a mod m)^b) mod m

Essential for RSA encryption!

Worked Examples

Example 1: Clock Addition

What time is 9 + 5 hours on a 12-hour clock?
(9 + 5) mod 12 = 14 mod 12 = 2
Answer: 2 o'clock

Example 2: Modular Multiplication

Calculate (12 x 15) mod 7
12 mod 7 = 5, 15 mod 7 = 1
(5 x 1) mod 7 = 5
Verify: 180 mod 7 = 5 ✓

Example 3: Negative Result

Calculate (3 - 8) mod 5
3 - 8 = -5
-5 mod 5 = 0 (add 5 until positive)
Or: (3 mod 5 - 8 mod 5 + 5) mod 5 = (3 - 3 + 5) mod 5 = 0

Example 4: Modular Exponentiation

Calculate 3^5 mod 7
3^1 mod 7 = 3
3^2 mod 7 = 9 mod 7 = 2
3^4 mod 7 = 2^2 mod 7 = 4
3^5 = 3^4 x 3^1 = 4 x 3 = 12 mod 7 = 5

Quick Fact

Modular arithmetic is the foundation of RSA encryption, which secures most internet communications. When you see the padlock icon in your browser, modular exponentiation with huge prime numbers is protecting your data. The security relies on the fact that modular exponentiation is easy, but reversing it (finding discrete logarithms) is computationally infeasible.

Frequently Asked Questions

Why is modular arithmetic useful?

Beyond cryptography, modular arithmetic appears in checksums (ISBN numbers, credit cards), hash functions, random number generation, calendar calculations, and music theory (pitch classes form Z₁₂).

Can the modulus be negative?

By convention, the modulus is always positive. If you encounter negative moduli in programming, the behavior varies by language. Mathematically, we always use positive moduli.

What does "congruent modulo m" mean?

Two numbers are congruent mod m if they have the same remainder when divided by m. We write a ≡ b (mod m). For example, 17 ≡ 5 (mod 12) because both leave remainder 5.

How do I handle negative numbers?

Add the modulus until you get a positive result. For example, -3 mod 7 = (-3 + 7) mod 7 = 4. In programming, some languages return negative remainders – add m to normalize.

What is Fermat's Little Theorem?

If p is prime and a is not divisible by p, then a^(p-1) ≡ 1 (mod p). This powerful theorem simplifies modular exponentiation and is key to primality testing and RSA.

Can I divide in modular arithmetic?

Division means multiplying by the modular inverse. The inverse of a mod m exists only when gcd(a,m) = 1. For prime moduli, every non-zero element has an inverse.

Other Free Tools

Modulo Calculator – Find the Remainder of Division

Calculate the modulo or remainder of any division instantly with our free online modulo calculator. Essential for programming, number theory, and cryptography applications.

GCD / HCF Calculator – Find Greatest Common Divisor Online

Calculate the GCD or HCF of two or more numbers instantly with our free online calculator. Uses the Euclidean algorithm to find the greatest common divisor with step-by-step solutions.

LCM Calculator – Find Least Common Multiple Online

Calculate the Least Common Multiple (LCM) of two or more numbers instantly with our free online LCM calculator. Get accurate results with step-by-step explanations.

Euler's Totient Function Calculator – Compute φ(n) Online

Calculate Euler's totient function φ(n) for any integer with our free online calculator. Find the count of integers up to n that share no common factor with n.

Divisibility Checker – Test Divisibility Rules Instantly

Check if any number is divisible by another with our free online divisibility checker. Displays the relevant divisibility rule and provides instant yes or no results.

Divisibility Check 2–20 – Test Divisibility for All Numbers

Check divisibility by all integers from 2 to 20 with a single input using our free online divisibility tool. Displays divisibility results with the rules used for each.

Binary Addition & Subtraction Calculator – Compute in Base 2

Add and subtract binary numbers step by step with our free online binary calculator. See each bit-by-bit operation clearly – perfect for computer science and digital electronics.

Prime Number Checker – Is It Prime? Find Out Instantly

Check if any number is prime or composite instantly with our free online prime number checker. Fast, accurate prime testing for any positive integer with a clear explanation.