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 7Result
Calculation
(17 + 5) mod 7 = 1The 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 m | 14 | 23 | 12 | 1 |
| (a-b) mod m | 5 | 18 | 7 | 1 |
| (a*b) mod m | 7 | 8 | 10 | 6 |
| a^b mod m | 2 | 10 | 1000 | 24 |
| a^b mod m | 3 | 100 | 7 | 4 |
| (a+b) mod m | -3 | 8 | 5 | 0 |
| Inverse | 3 | - | 7 | 5 (3x5=15, 15 mod 7=1) |
Related Calculators
Exponent Calculator
Calculate powers before applying modular reduction.
Log Calculator
Compute logarithms related to discrete logarithm problems.
Root Calculator
Calculate roots that connect to modular square roots.
Matrix Calculator
Matrix operations can also be performed in modular arithmetic.
Percentage Calculator
Remainder-based calculations for everyday percentage problems.
Random Number Generator
Random number algorithms use modular arithmetic internally.
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:
- Start with a = 7, b = 13, m = 11
- Express 13 in binary: 13 = 1101 in base 2 (8 + 4 + 1)
- 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
- Combine: 7^13 = 7^8 x 7^4 x 7^1 = 9 x 3 x 7 = 189
- 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
- Khan Academy — Modular Arithmetic: khanacademy.org
- Wolfram MathWorld — Modular Arithmetic: mathworld.wolfram.com
- NIST — Cryptographic Standards and Guidelines: csrc.nist.gov
Disclaimer: This calculator is for informational and educational purposes only. Results are estimates and may not reflect exact values.
Last updated: November 3, 2026