Multiplicative inverse in modular arithmetic calculator

Compute modular inverses instantly with clear inputs and robust validation. Pick Extended Euclid or Fermat for verified prime moduli. Try Binary EEA for efficient coefficient updates too. Run batch jobs, upload CSV, export to PDF. See steps, factor insights, and verify residues precisely today.

Separators accepted: comma, semicolon, or space.
Results

Enter values and press Compute inverse to see results here.

Example data table
amInverseCheck (a×inv mod m)
31141
1017121
726151
1743381
3564111
19121511
Example of using this calculator
  1. Find inverse: For a=17, m=43, the calculator returns 38. Verification: 17 × 38 ≡ 1 (mod 43).
  2. Modular division: Compute 23 ÷ 17 (mod 43) as 23 × inv(17) (mod 43) = 14.
  3. Large composite modulus: Invert 17 modulo 3120. Result: 2753. Check: 17 × 2753 ≡ 1 (mod 3120).

You can reproduce each step: enter the values above, select a method, and compare the verification column with these results.

Formula used

The inverse of a modulo m is a number x satisfying a·x ≡ 1 (mod m). It exists iff gcd(a,m)=1.

  • Extended Euclidean: Solve x·a + y·m = gcd(a,m). If gcd=1, inverse is x mod m.
  • Binary EEA: Uses subtraction and halving for efficient coefficient updates.
  • Fermat (prime m): If m is prime and a not divisible by m, then a^(m-2) mod m equals the inverse.
How to use this calculator
  1. Enter integers for a and m. Modulus must be nonzero.
  2. Choose a method: prefer Extended Euclidean; Binary is also robust.
  3. Check “factor insights” to see prime-power analysis and partial inverses.
  4. Use batch area or upload CSV for many pairs.
  5. Export your results as CSV or PDF for sharing.
Key facts in ℤm about inverses
SettingConditionExistence of inverseHow to compute
General modulus m gcd(a, m) = 1 Exists and is unique mod m Extended Euclid or Binary EEA
Prime modulus p a ≢ 0 (mod p) Always exists EEA or Fermat: ap−2 mod p
Prime power pk p ∤ a Exists EEA modulo pk (Hensel lifting optional)
Composite m with CRT gcd(a, m) = 1 Exists Invert mod each prime-power, combine via CRT
Method comparison and complexity
MethodWorks forTime (rough)ProsCons
Extended Euclidean Any m O(log m) Deterministic, returns Bézout coefficients Needs divisions
Binary EEA Any m O(log m) Uses shifts/subtractions, simple arithmetic Trace a bit longer
Fermat ap−2 mod p Prime m O(log p) multiplications Easy with fast exponentiation Invalid if m is composite
Edge cases and diagnostics
  • If gcd(a, m) ≠ 1, inverse does not exist; show gcd and Bézout.
  • Negative a are normalized: result in [0, m−1] for clarity.
  • Fermat method auto-checks primality to prevent misuse.
amgcd(a,m)InverseOutcome
14217No inverse (not coprime)
077No inverse (not coprime)
-51119Inverse exists
123513Inverse exists
Applications and mini‑examples
ApplicationTaskHow inverse is used
Modular division Solve a·x ≡ b (mod m) x ≡ b·a−1 (mod m) when gcd(a,m)=1
Chinese Remainder Theorem Combine solutions mod coprime moduli Needs inverses of moduli residues to build recombination weights
RSA key math Compute d from e·d ≡ 1 (mod φ(n)) d = e−1 mod φ(n) via EEA
Elliptic curves Point addition in finite fields Slope = (y₂−y₁)·(x₂−x₁)−1 mod p
Frequently Asked Questions
1) When does a modular inverse exist?

For a modulo m, an inverse exists only when gcd(a, m) = 1. If the gcd is not one, the equation a·x ≡ 1 (mod m) has no solution, and modular division by a is undefined.

2) Which method should I choose?

Extended Euclidean is the default, fast, and deterministic for any modulus. Binary EEA avoids divisions using shifts. Fermat’s method works only for prime moduli and uses fast exponentiation a^(p−2) mod p.

3) Can I use negative a values?

Yes. The calculator normalizes inputs and outputs into the standard residue class. The reported inverse is always shown within the range [0, m−1] to simplify verification and downstream computations.

4) Why does Fermat fail sometimes?

Fermat’s method requires a prime modulus p and a not divisible by p. If the modulus is composite, a^(p−2) mod p is invalid. The tool auto-checks primality and warns to prevent misuse.

5) How do I solve a·x ≡ b (mod m)?

First compute a’s inverse modulo m, provided gcd(a, m) = 1. Then x ≡ b·a^(−1) (mod m). Enter a and m, get the inverse, and multiply by b modulo m to obtain the solution.

6) What if gcd(a, m) ≠ 1 but I still need a solution?

There is no inverse, but a·x ≡ b (mod m) may have solutions if gcd(a, m) divides b. Reduce by the gcd and solve in the smaller modulus, or factor m and use the Chinese Remainder Theorem.

7) How large can inputs be?

This tool handles typical 64‑bit sized moduli comfortably. Extended Euclid and Binary EEA scale logarithmically. For extremely large cryptographic sizes, specialized big‑integer libraries and optimized number‑theoretic implementations are recommended.

Notes and tips
  • If gcd(a,m) ≠ 1, an inverse modulo m does not exist.
  • Negative a are allowed; output is normalized into [0, m-1].
  • “Fermat” auto-checks primality using Miller–Rabin to avoid misuse.

Related Calculators

Inverse Function Finder CalculatorPolynomial Long Division Calculatorroots of cubic equation calculatorquadratic function from 3 points calculatorWeighted linear regression calculatorremainder and factor theorem calculatordivide using long division calculatorsynthetic division remainder calculatorLCM fraction Calculatorfactor polynomials by grouping calculator

Important Note: All the Calculators listed in this site are for educational purpose only and we do not guarentee the accuracy of results. Please do consult with other sources as well.