Skip to content
Embed

Paste this on your site. The attribution link is required and is what makes embedding free.

Modular Arithmetic Calculator — Free Online Mod Calculator

Perform modular arithmetic operations including addition, subtraction, multiplication, and exponentiation with GCD and modular inverse calculations.

Expression

(17 + 5) mod 7

Result

1

Calculation

(17 + 5) mod 7 = 1

The result of (17 + 5) mod 7 is 1. The answer is always in the range [0, 6].

a mod m

3

b mod m

5

gcd(a, m)

1

Modular Inverse (a⁻¹ mod m)

5

Modular Arithmetic Quick Reference Table

Operation a b mod Result
(a+b) mod m1423121
(a-b) mod m51871
(a*b) mod m78106
a^b mod m210100024
a^b mod m310074
(a+b) mod m-3850
Inverse3-75 (3x5=15, 15 mod 7=1)

Related Calculators

About this calculator

Modular Arithmetic Formulas

Modular Addition

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

Modular Subtraction

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

Modular Multiplication

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

Modular Exponentiation

a^b mod m (computed via square-and-multiply)

Modular Inverse

a^(-1) mod m: find x such that (a x x) mod m = 1

Variables Explained

  • a (First Operand): The first integer in the operation. For exponentiation, this is the base. Any integer is valid — the calculator reduces it modulo m internally.
  • b (Second Operand/Exponent): The second integer. For exponentiation, b must be a non-negative integer (the exponent). For other operations, any integer works.
  • m (Modulus): The positive integer that defines the arithmetic system. Results are always in [0, m-1]. Common moduli include primes (for cryptography), powers of 2 (for computing), 10 (for check digits), 12 (for clocks), and 7 (for days of the week).
  • gcd(a, m): The greatest common divisor. If gcd(a, m) = 1, the modular inverse of a exists. If gcd(a, m) > 1, no modular inverse exists.

Step-by-Step Example

Calculate 7^13 mod 11:

  1. Start with a = 7, b = 13, m = 11
  2. Express 13 in binary: 13 = 1101 in base 2 (8 + 4 + 1)
  3. Square-and-multiply: 7^1 mod 11 = 7, 7^2 mod 11 = 49 mod 11 = 5, 7^4 mod 11 = 5^2 mod 11 = 25 mod 11 = 3, 7^8 mod 11 = 3^2 mod 11 = 9
  4. Combine: 7^13 = 7^8 x 7^4 x 7^1 = 9 x 3 x 7 = 189
  5. 189 mod 11 = 189 - 17 x 11 = 189 - 187 = 2

By Fermat's Little Theorem, since 11 is prime, 7^10 mod 11 = 1. So 7^13 = 7^10 x 7^3 = 1 x 343, and 343 mod 11 = 2. Both methods confirm the answer.

Sources

Disclaimer: This calculator is for informational and educational purposes only. Results are estimates and may not reflect exact values.

Last updated: November 3, 2026