Modular Arithmetic Calculator

Calculate modular arithmetic operations: a mod n, modular addition, subtraction, multiplication, and exponentiation.

Any integer (negative allowed)
Must be > 0
17 mod 5
2
17 = 3 * 5 + 2
Quotient
3
floor(17 / 5) = 3
Modular Inverse
3
17 * 3 = 1 (mod 5)
Euler's Totient phi(n)
4
4 integers in [1, 5] are coprime to 5
GCD(a, n)
1
17 and 5 are coprime
17^3 mod 5
3
Modular exponentiation (square-and-multiply)
Fermat's Test
Passes
17^4 mod 5 = 1 (Fermat verified)
Remainder Position (0 to 4)
2 / 4
Congruence Class [2] (mod 5)
-13-8-32712172227...
All integers congruent to 2 (mod 5)
Multiplication Table (mod 12)
2-15 for readability
*01234567891011
0000000000000
101234567891011
202468100246810
3036903690369
4048048048048
505103816114927
6060606060606
707294116183105
8084084084084
9096309630963
1001086420108642
1101110987654321
Green = 1 (inverse pairs) / Red = 0 (zero divisors)
Powers of 17 mod 5
k17^k17^k mod 5Trail
011
1172
22894
34,9133
483,5211 <- order
51,419,8572
624,137,5694
Modular Arithmetic Properties
PropertyFormulaExample with a=17, n=5
Remaindera mod n2
Addition(a + a) mod n4
Multiplication(a * a) mod n4
Additive inverse(n - a mod n) mod n3
Totient identitya^phi(n) mod n (if coprime)1
Planning notes, formulas, and examples

About the Modular Arithmetic Calculator

The Modular Arithmetic Calculator computes a mod n (the remainder when a is divided by n) and performs modular addition, subtraction, and multiplication. Modular arithmetic is "clock arithmetic" — numbers wrap around after reaching the modulus.

Modular arithmetic is foundational in number theory, cryptography (RSA, Diffie-Hellman), computer science (hash functions, checksums), and everyday life (12-hour clocks, days of the week).

This calculator handles positive and negative numbers, always returning a non-negative result. It also performs modular exponentiation (a^b mod n), which is crucial in public-key cryptography.

When This Page Helps

Modular arithmetic with large numbers, especially exponentiation, is computationally intensive. This calculator handles all operations including modular exponentiation.

How to Use the Inputs

  1. Enter the number a.
  2. Enter the modulus n.
  3. View a mod n (the remainder).
  4. See the quotient and verify: a = quotient × n + remainder.
  5. For modular exponentiation, enter the exponent b.
Formula used
a mod n = a − n × floor(a/n) Properties: (a + b) mod n = ((a mod n) + (b mod n)) mod n (a × b) mod n = ((a mod n) × (b mod n)) mod n

Example Calculation

Result: 2

17 mod 5: 17 = 3 × 5 + 2. The remainder is 2. Equivalently, 17 and 2 are congruent modulo 5.

Tips & Best Practices

  • a mod n always gives a result between 0 and n−1.
  • Negative numbers: (−7) mod 5 = 3, because −7 = (−2)×5 + 3.
  • Modular arithmetic preserves addition and multiplication.
  • The 12-hour clock is mod 12 arithmetic.
  • ISBN check digits use mod 11 or mod 10 arithmetic.
  • RSA encryption uses modular exponentiation with very large numbers.

Modular Arithmetic in Cryptography

RSA encryption computes c = m^e mod n for encryption and m = c^d mod n for decryption. The security relies on the difficulty of factoring n into its prime components.

Clock Arithmetic

A 12-hour clock is mod 12: 10 o'clock + 5 hours = 3 o'clock. Days of the week cycle with mod 7. Calendar calculations routinely use modular arithmetic.

Modular Inverse

a has a modular inverse mod n if gcd(a, n) = 1. The inverse a⁻¹ satisfies a × a⁻¹ ≡ 1 (mod n). Extended Euclidean algorithm computes it.

Professionals in data science, engineering, and finance apply these calculations daily to model complex systems and test analytical hypotheses.

Sources & Methodology

Last updated:

Frequently Asked Questions

  • Modular arithmetic is a system where numbers "wrap around" after reaching a certain value (the modulus). It is like clock arithmetic: 10 + 5 = 3 on a 12-hour clock.