Modular Arithmetic Calculator

Calculate a mod n, modular addition, multiplication, and fast exponentiation a^b mod n. Essential for cryptography, hash functions, and number theory.

🔢 Number Theory📐 a mod n = remainder of a ÷ n🔢 Math
Operation
Value a
Modulus n
Value b
Please enter valid values.

Formula & Reference

VariableSymbolFormulaUnits
Modular Arithmetic Calculatora mod n = remainder of a ÷ n0 to n-1

Step-by-Step Examples

Example 1
Simple

17 mod 5

  • 17=3×5+2, remainder=2
✓ 2
Example 2
Multiplication

(7×8) mod 12

  • 56=4×12+8, result=8
✓ 8
Example 3
Fast exponentiation

3^10 mod 7

  • 3²≡2, 3⁴≡4, 3⁸≡2 (mod 7)
  • 3^10=3^8·3^2≡2·2=4
✓ 4

Real-World Applications

Common Mistakes to Avoid

⚠️
Negative numbers

(-7) mod 3 = 2 mathematically. Use ((a%n)+n)%n to handle negatives.

⚠️
Don't compute a^b directly

For large b, use repeated squaring to avoid overflow.

⚠️
Mod vs remainder

Mathematical mod is always non-negative; computer % can be negative.

Frequently Asked Questions

What is modular arithmetic?
Numbers wrap around at n. Like a clock face.
a≡b (mod n)?
Same remainder when divided by n. n divides (a-b).
Modular inverse?
x such that a·x≡1 (mod n). Used in RSA decryption.
What is RSA?
Encrypt: m^e mod n. Decrypt: c^d mod n.
Chinese Remainder Theorem?
Unique solution to system of congruences with coprime moduli.

Related Math Calculators

Formula Explorer connections

Interpretation: This formula uses integer divisibility, modular arithmetic, finite fields or coding relationships. Assumption: Inputs are usually integers with specific modulus or coprimality requirements. Cryptographic examples are educational and not a substitute for vetted security libraries.

Modular Inverse and Extended Euclidean Calculator →Parity Bit Calculator →Prime Factorization Calculator – Factor Any Number →Math Formula Explorer →