Modular Inverse Calculator
Compute the modular multiplicative inverse of an integer a modulo m using the extended Euclidean algorithm.
How does this calculator work?
The modular inverse of a modulo m is the integer x in [0, m) where a·x ≡ 1 (mod m). It exists only when gcd(a, m) = 1, and is found with the extended Euclidean algorithm, then normalized to a positive residue. If a and m share a factor, no inverse exists.
Formula
How this is calculated
The number a is reduced modulo m into the range [0, m), and the modulus m must be an integer greater than 1. The extended Euclidean algorithm is then run on (a mod m, m), producing both the greatest common divisor gcd(a, m) and a Bezout coefficient x such that a·x + m·y = gcd(a, m).
A modular inverse exists only when gcd(a, m) = 1. When it does, the raw coefficient x can be negative, so it is normalized into [0, m) with ((x mod m) + m) mod m. The returned inverse satisfies (a · x) mod m = 1, shown in the verification stat. If gcd(a, m) ≠ 1, no inverse exists and the divisor is reported instead.
All arithmetic uses BigInt internally to avoid precision loss with large integers. Inputs must be integers; non-integer values are rejected. Negative values of a are handled by reduction, so for example -8 mod 11 is treated as 3.
Frequently asked questions
An inverse of a modulo m exists only when a and m are coprime, that is gcd(a, m) = 1. If they share a common factor greater than 1, no integer x satisfies a·x ≡ 1 (mod m).
No. The modulus can be any integer greater than 1. When m is prime, every a from 1 to m−1 has an inverse because all are coprime to m, but composite moduli also work for any a coprime to m.
The number a is first reduced into the range [0, m) before the algorithm runs, so negative inputs are treated by their positive residue. The resulting inverse is also normalized to lie in [0, m).
Also known as
TG we-Calculate Editorial Team. (2026). Modular Inverse Calculator [Online calculator]. TG we-Calculate. https://we-calculate.com/calculator/modular-inverse-calculator
TG we-Calculate Editorial Team. "Modular Inverse Calculator." TG we-Calculate. 2026. https://we-calculate.com/calculator/modular-inverse-calculator.
TG we-Calculate Editorial Team, "Modular Inverse Calculator," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/calculator/modular-inverse-calculator
@misc{wecalculate_modular_inverse_calculator, title = {Modular Inverse Calculator}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/calculator/modular-inverse-calculator}}, year = {2026}, note = {TG we-Calculate} }
Did this calculator help you?
