Logo

MonoCalc

/

Modular Inverse Calculator

Math

Try:

Values may be up to 300 digits — every computation uses BigInt so large, cryptographic-scale numbers stay exact.

Modular inverse

38

Inverse exists

GCD(17, 43)

1

Bezout coefficients

x=-5, y=2

a·x + m·y = gcd, i.e. 17·(-5) + 43·(2) = 1

Verified

(17 × 38) mod 43 = 1

Extended Euclidean Algorithm

RowRemainder (r)Quotient (q)st
01710
14301
217010
392-21
4813-1
511-52
60843-17

The algorithm stops once the remainder hits 0, leaving GCD = 1.

About This Tool

Modular Inverse Calculator – Extended Euclidean Algorithm Explained

The modular multiplicative inverse of an integer a modulo m is the integer x that satisfies (a × x) mod m = 1. It plays the same role in modular arithmetic that a reciprocal plays in ordinary arithmetic — instead of dividing by a, you multiply by its inverse. This calculator finds that inverse using the Extended Euclidean Algorithm, shows every row of the working, verifies the result, and can also solve linear congruences or build a full inverse lookup table.

When Does an Inverse Exist?

A modular inverse of a exists modulo m if and only if a and m are coprime — that is, gcd(a, m) = 1. If they share any common factor greater than 1, no multiple of a can ever land exactly on 1 modulo m, so the calculator reports that no inverse exists along with the shared GCD instead of returning a meaningless number.

How the Extended Euclidean Algorithm Works

The plain Euclidean algorithm finds gcd(a, m) by repeatedly replacing the larger value with the remainder of dividing it by the smaller one. The extended version tracks two extra running coefficients, s and t, at every row so that a·s + m·t always equals that row's remainder — an identity known as Bezout's identity. When the remainder finally reaches 1, its s coefficient, reduced into the range [0, m), is exactly the modular inverse. Because both the GCD and the Bezout coefficients fall out of the same table, the calculator can show the full working in a single pass rather than a separate back-substitution step.

Bezout's identity in one line
For any integers a and m, there exist integers x and y such that a·x + m·y = gcd(a, m). When the GCD is 1, that x (taken modulo m) is the modular inverse.

Solving Linear Congruences

An equation of the form ax ≡ b (mod m) is a linear congruence, and it has a single solution modulo m whenever gcd(a, m) = 1. The congruence solver mode finds the inverse of a first, then computes x = (inverse(a, m) × b) mod m. If a and m are not coprime, this approach cannot produce a single answer, and the tool explains why rather than guessing.

Batch Inverse Tables

Many applications — building lookup tables, checking which residues are units in a ring, or preparing an affine cipher key — need the inverse of several numbers under the same modulus at once. Batch mode runs the same Extended Euclidean computation across every value you list, flags any entry that has no inverse, and reports invalid tokens individually so one typo never blocks the rest of the table.

Why It Matters in Cryptography

Modular inverses are a working ingredient of RSA key generation: the private decryption exponent is computed as the modular inverse of the public encryption exponent, taken modulo Euler's totient of the RSA modulus. The same operation underlies error-correcting codes, hash-based data structures, and any scheme that needs to reverse a multiplication performed modulo m. Because these moduli can run to hundreds of digits, this calculator parses every value as a BigInt so precision never degrades the way ordinary floating-point numbers would past 2^53.

Reading the Output and Limits

Every mode shows a clear inverse-or-not verdict, the GCD that explains it, and a verification line confirming (a × inverse) mod m = 1. The step table displays each row of the Extended Euclidean Algorithm together with its running Bezout coefficients, and results can be copied, downloaded as text or CSV, or shared through a link that restores every input. Values accept up to 300 digits each; a modulus of exactly 1 is treated as a degenerate case (every integer is congruent to 0) rather than an error, and a = 0 is always reported as having no inverse for any modulus greater than 1.

Frequently Asked Questions

Is the Modular Inverse Calculator free?

Yes, Modular Inverse Calculator is totally free :)

Can I use the Modular Inverse Calculator offline?

Yes, you can install the webapp as PWA.

Is it safe to use Modular Inverse Calculator?

Yes, any data related to Modular Inverse Calculator only stored in your browser (if storage required). You can simply clear browser cache to clear all the stored data. We do not store any data on server.

How does this modular inverse calculator work?

It runs the Extended Euclidean Algorithm on a and m, which finds gcd(a, m) while simultaneously tracking the Bezout coefficients x and y such that a·x + m·y = gcd(a, m). If the gcd is 1, the inverse is x reduced into the range [0, m), and the tool verifies the result by checking that (a × inverse) mod m equals 1.

Why does a modular inverse sometimes not exist?

A modular inverse of a modulo m exists only when a and m are coprime, i.e. gcd(a, m) = 1. If they share any common factor greater than 1, no integer x can satisfy (a × x) mod m = 1, and the calculator reports that no inverse exists along with the shared gcd.

What is the Linear Congruence Solver mode for?

It solves equations of the form ax ≡ b (mod m) for x. The solver first finds the modular inverse of a, then computes x = (inverse × b) mod m. A unique solution exists only when gcd(a, m) = 1; otherwise the tool explains why no single solution can be derived this way.

What do the Bezout coefficients mean?

Bezout's identity states that for any integers a and m, there exist integers x and y such that a·x + m·y = gcd(a, m). When gcd(a, m) = 1, that same x (reduced modulo m) is exactly the modular inverse, which is why the Extended Euclidean Algorithm computes both quantities in a single pass.

How large can a and m be?

Both values are parsed as BigInt and accept up to 300 digits each, so cryptographic-scale numbers such as RSA moduli compute without any loss of precision. The Extended Euclidean Algorithm converges in only a few thousand steps even at that size, keeping the calculation fast in the browser.

Why is the modular inverse important in cryptography?

RSA key generation computes the private decryption exponent as the modular inverse of the public exponent modulo Euler's totient of the RSA modulus. Modular inverses also appear in solving linear congruences, error-correcting codes, and hashing schemes wherever a multiplicative operation modulo m needs to be undone.