Modular Arithmetic Calculator
Perform modular addition, multiplication, and exponentiation. Calculate (a op b) mod m with equivalence classes.
About this calculator
This calculator evaluates one of three modular operations — addition, multiplication, or exponentiation — and reduces the result to its remainder under a chosen modulus, always reporting a value between 0 and one less than the modulus, never a negative remainder even when a or b is negative. Of the three numeric fields, the modulus carries by far the largest influence on the answer: shrinking or growing the modulus while holding a and b fixed reshapes the entire span the result can fall into, whereas nudging a or b only shifts where inside that span the answer lands. For the Power operation the calculator does not multiply the base by itself repeatedly and then take a remainder at the very end — that would overflow standard number precision almost immediately for a modulus in the thousands.
Instead it uses modular exponentiation by repeated squaring, reducing the running value after every multiplication so nothing grows past the modulus squared. What this tool does not do: it never computes a modular inverse or performs modular division, so it cannot solve an equation like a times x is congruent to b for the unknown x — that class of problem belongs to a linear congruence solver, not a straightforward evaluator. It also silently raises a modulus of zero or a negative modulus up to 1 rather than reporting the input as invalid.
Inputs
Results
Result
9
How to Use This Calculator
- Enter a, b, and Modulus (m).
- Set Operation, Addition (a + b) mod m, and Multiplication (a * b) mod m.
- Adjust Power (a^b) mod m as needed.
- Review the Result result.
- Use Expression and Equivalence Class to inform your decision.
How the result changes with Modulus (m)
| Modulus (m) | Result |
|---|---|
| 6.5 | 4 |
| 9.75 | 4 |
| 20 | 2 |
| 33 | 22 |
What each input means
- a
- First operand
- b
- Second operand
- Modulus (m)
- The modulus value
- Operation
- Modular operation to perform
How this is calculated
Worked example, using the default values
- Identify Input Parameters4 parametersa = 17, b = 5, Modulus (m) = 13, Operation = 1 = 4 input(s) provided
- Calculate Result9 = 9
- Calculate Equivalence ClassEquivalence Class{..., -17, -4, 9, 22, 35, ...} = {..., -17, -4, 9, 22, 35, ...}
Engine last updated . Checked against 6 independently-derived tests — how we verify calculators. Built by Paul Gunder, a software engineer, not a licensed financial, medical, or legal professional.
Frequently Asked Questions
Why is the result never negative, even if I enter negative numbers for a or b?
JavaScript's built-in percent operator can return a negative remainder when the dividend is negative, so the calculator applies the modulus twice — once to fold the raw operands into range, and a second time after combining them — to guarantee the reported result always lands between 0 and one less than the modulus.
Why does the Power operation not just multiply the base by itself and reduce once at the end?
Multiplying a base by itself dozens of times before ever reducing would quickly produce numbers far too large for standard floating-point precision to represent exactly, especially with a modulus in the thousands. The calculator instead reduces after every squaring step, a technique called modular exponentiation, which keeps every intermediate value smaller than the modulus squared.
What is the equivalence class shown below the result?
It lists a handful of the infinitely many integers that share the same remainder as your answer when divided by the modulus — the result itself, plus and minus one modulus, and plus and minus two moduli. Every number spaced one modulus apart from it in either direction would produce the identical result under this modulus.
Can this calculator solve for an unknown value in an equation like 3x is congruent to 5 mod 7?
No. This tool only evaluates a fully specified addition, multiplication, or exponentiation expression and reports the remainder — it does not search for an unknown x satisfying a congruence. Solving that kind of equation requires finding a modular inverse, which is a different calculation this page does not perform.
Related Calculators
The questions that sit next to this one — chosen by subject, including calculators filed under a different category.
Chinese Remainder Theorem Calculator
Solve systems of congruences using the Chinese Remainder Theorem. Find x such that x ≡ r1 (mod m1) and x ≡ r2 (mod m2).
Number TheoryEuler's Totient Calculator
Calculate Euler's totient function phi(n) — the count of integers from 1 to n that are coprime to n.
DivingNitrox Blend Calculator
Calculate Maximum Operating Depth (MOD), Equivalent Air Depth (EAD), best mix, and oxygen toxicity limits for Nitrox/EANx diving.
Number TheoryContinued Fraction Calculator
Convert a fraction to its continued fraction representation. Shows coefficients, convergents, and approximation error.
More in Math & Statistics.