Updated Math

Modular Inverse Calculator

Find a⁻¹ (mod m) fast using the Extended Euclidean Algorithm. See gcd(a,m), the normalized a mod m, a verification check, and optional step-by-step work with history and CSV export.

Extended Euclid Big Integer Safe Steps Table History + CSV

Modular Inverse Evaluator

Enter integers a and m to compute the inverse a⁻¹ modulo m (if it exists). Toggle output style and show steps for the Extended Euclidean Algorithm.

The number you want to invert. Can be negative.
Typically a positive integer. The inverse exists only if gcd(a,m)=1.
Tip: If you’re trying to compute b ÷ a (mod m), first find a⁻¹ (mod m), then multiply: b×a⁻¹ (mod m).
Item Symbol Meaning Example
Value a The number you want to invert a = 3
Modulus m The modulus defining the number system m = 11
Inverse a⁻¹ Number x such that a×x ≡ 1 (mod m) 3×4 ≡ 1 (mod 11)
Existence condition gcd(a,m)=1 Inverse exists only when a and m are coprime gcd(3,11)=1
Normalization a mod m Reduce a into a standard representative class −3 mod 11 = 8

Quick Steps

  1. Enter integers a and m.
  2. Press Calculate to compute gcd(a,m).
  3. If gcd = 1, the calculator returns the inverse a⁻¹ (mod m).
  4. Check the verification result: (a×a⁻¹) mod m should equal 1.
  5. Turn on Show Steps to view the Extended Euclid table.
Common checks: If a = 0 or m ≤ 1, no modular inverse exists. If gcd(a,m) ≠ 1, modular “division” by a is undefined.
Your modular inverse history will appear here after you calculate.

What Is a Modular Inverse?

A modular inverse is the “undo” button for multiplication in modular arithmetic. If you have a number a and a modulus m, the modular inverse of a is a number x such that: a × x ≡ 1 (mod m). That means when you multiply a by x, the result behaves like 1 once you reduce it modulo m.

People often describe this as “division in modular arithmetic,” because instead of dividing by a, you multiply by a⁻¹. For example, if you want to solve a × y ≡ b (mod m) and the inverse exists, then the solution is y ≡ b × a⁻¹ (mod m). The important catch is that modular inverses don’t always exist.

When Does an Inverse Exist?

The inverse exists exactly when a and m are coprime, meaning their greatest common divisor is 1: gcd(a, m) = 1. If a shares a factor with m, then multiplying by a collapses several residues together and there’s no way to “undo” it uniquely. In that case, the calculator correctly reports “no inverse.”

This rule explains a lot of intuition: modulo a prime number p, every non-zero number has an inverse. That’s because if p is prime and a is not a multiple of p, then gcd(a,p)=1 automatically. In contrast, with composite moduli, some numbers are invertible and some are not.

How Do You Calculate a Modular Inverse?

There are multiple ways to compute inverses, but the most reliable general method is the Extended Euclidean Algorithm. It works for any integers a and m and gives you:

  • The gcd of a and m
  • Coefficients x and y such that a x + m y = gcd(a,m)

If gcd(a,m)=1, the identity becomes a x + m y = 1. Taking both sides modulo m removes the m y term, leaving a x ≡ 1 (mod m). That means x is the inverse (possibly negative), and the usual final step is to reduce it into a standard range such as 0…m−1.

Why Normalize “a mod m” First?

In modular arithmetic, numbers that differ by a multiple of m are considered equivalent. So a and a + k m represent the same residue class. Normalizing simply picks a convenient representative for the class. This is especially helpful when a is negative. For instance, −3 mod 11 is the same class as 8, because −3 and 8 differ by 11.

The inverse relationship respects this equivalence: if you replace a by a mod m, the inverse is unchanged in meaning, and the verification check still comes out as 1.

What Does the Verification Result Mean?

A good modular inverse calculator should verify its work. The simplest check is: (a × inverse) mod m. If an inverse exists, this value should equal 1. If you see anything else, it means the inverse does not exist or the inputs were invalid.

Verification is also a helpful sanity check when you work by hand. Even if your computed inverse is negative or larger than m, the verification still works because you reduce modulo m at the end.

Why Can the Same Inverse Be Written Many Ways?

If x is an inverse, then x + m is also an inverse, and so is x − m. That’s because adding or subtracting a multiple of m doesn’t change the residue class. Many tools display the least non-negative inverse in the range 0 to m−1, because it’s compact and standard.

Sometimes, a symmetric representation is more convenient: you choose an equivalent value closer to 0 (possibly negative). This can make manual algebra feel simpler, especially when you expect cancellations.

How to Use the Calculator for Modular Division

Modular arithmetic does not define division directly. Instead, division by a is multiplication by the inverse of a, if it exists. If you want to compute b ÷ a (mod m), do this:

  1. Compute a⁻¹ (mod m).
  2. Compute b × a⁻¹ (mod m).
  3. Reduce the result modulo m.

If gcd(a,m) ≠ 1, then there is no inverse and the division problem may have no solution or multiple solutions depending on b. The inverse calculator helps you detect that immediately.

Worked Example You Can Try Right Now

Suppose a = 3 and m = 11. We want x such that 3x ≡ 1 (mod 11). The calculator returns x = 4 (least non-negative), because 3×4 = 12 and 12 mod 11 = 1. In symmetric form, 4 is already close to 0, so it stays the same.

Try another example: a = 10 and m = 17. The calculator will return an inverse because gcd(10,17)=1. Verify it by multiplying and reducing mod 17. This is a good habit when you’re building confidence in a modular workflow.

What If There Is No Inverse?

If gcd(a,m) ≠ 1, the calculator reports “no inverse exists.” That is not a minor technicality; it means the modular system cannot uniquely reverse multiplication by a. For example, take a = 6 and m = 15. gcd(6,15)=3, so there is no number x that satisfies 6x ≡ 1 (mod 15).

This matters in equations. If you try to solve 6y ≡ b (mod 15), the equation is solvable only when b is a multiple of 3, and even then it may have multiple solutions. The modular inverse exists specifically to make “divide by a” valid, and that requires coprime inputs.

Why Extended Euclid Works So Well

The Extended Euclidean Algorithm is fast, deterministic, and works on integers without needing prime moduli. It repeatedly applies division with remainder (the same idea behind the standard gcd algorithm) while tracking how each remainder can be written as a combination of the original inputs.

The steps table in this tool shows the evolving values used to compute coefficients. Even if the intermediate numbers look unfamiliar, the big idea is simple: at the end of the process, one coefficient becomes the inverse when the gcd is 1.

How to Read the Steps Table

Each row corresponds to one iteration of the algorithm. The q column is the integer quotient from dividing old_r by r. The pairs (old_r, r) track the gcd remainders, while (old_s, s) and (old_t, t) track coefficients that express the current remainder as a combination of the original numbers.

If the final gcd is 1, the last coefficient associated with a (shown by the algorithm as old_s at termination) is the inverse up to reduction modulo m. The calculator handles the reduction and shows the inverse in your chosen output style.

Where Modular Inverses Show Up in Real Life

Cryptography and key math

Modular inverses are central in public-key cryptography. RSA relies on modular arithmetic over large integers, and many steps involve inverses under a modulus derived from primes. Elliptic curve systems also use inverses for point addition and slope calculations on finite fields.

Computer science and algorithms

Inverses appear in modular hashing, randomized algorithms, number theory utilities, and competitive programming problems. They’re especially useful when you need to divide under a modulus in a way that stays consistent and efficient.

Solving congruences and modular equations

Linear congruences of the form a x ≡ b (mod m) are everywhere in modular reasoning. If the inverse exists, the solution is immediate: x ≡ b a⁻¹ (mod m). If not, the gcd tells you exactly what conditions are required for solutions to exist.

What If You Change the Modulus?

A number can be invertible in one modulus and not invertible in another. For example, a = 2 has an inverse modulo 5 because gcd(2,5)=1, but it does not have an inverse modulo 6 because gcd(2,6)=2. This is why modular arithmetic is not “one-size-fits-all” and why the gcd check matters so much.

Tips for Avoiding Common Mistakes

Using m ≤ 1

Modulus 1 collapses every number to 0, so you can’t get a product congruent to 1. For m = 0, modular arithmetic is undefined. Use m ≥ 2 for meaningful inverses.

Forgetting to reduce a

If a is large or negative, reduce it: a mod m. This doesn’t change the true answer; it just makes it easier to reason about and verify.

Assuming “every number has an inverse”

Only numbers coprime to the modulus have inverses. In prime moduli, that means every non-zero number works; in composite moduli, you must check the gcd.

How to Use History for “What If?” Comparisons

History is useful when you’re exploring how invertibility changes across moduli. Try the same a with several different m values and compare gcd and inverse output. You’ll quickly see a pattern: when the gcd is 1, you get an inverse; when it isn’t, you don’t. Export to CSV if you want to keep a record for notes, teaching, or problem sets.

Limitations and Safe Use Notes

This tool is designed for integer modular arithmetic. It does not compute inverses for non-integers, and it treats the modulus as an integer system. If your problem involves fractions, floating-point values, or non-standard rings, use an appropriate algebra tool or transform the problem into integer form first.

For cryptographic use, correctness of the math is necessary but not sufficient: real-world security depends on protocols, randomness, key sizes, constant-time operations, and careful implementation. Use this calculator for learning, verification, and planning rather than production cryptographic operations.

FAQ

Modular Inverse Calculator – Frequently Asked Questions

Quick answers about modular inverses, when they exist, and how Extended Euclid finds them.

The modular inverse of a modulo m is a number x such that a×x ≡ 1 (mod m). It is written as a⁻¹ (mod m) and it only exists when a and m are coprime.

A modular inverse exists if and only if gcd(a, m) = 1 (meaning a and m share no common factor other than 1). If gcd(a, m) ≠ 1, there is no inverse and “division” by a is not possible modulo m.

It finds integers x and y such that ax + my = gcd(a, m). If gcd(a, m) = 1, then ax + my = 1, so ax ≡ 1 (mod m). That x (reduced mod m) is the modular inverse.

It is the number you multiply by a to “undo” multiplication by a under modulus m. It is the modular equivalent of 1/a, but it only exists for coprime inputs.

Yes. A negative a is first reduced into the range modulo m (for example, −3 mod 11 becomes 8). The inverse is computed with the normalized value automatically.

If x is an inverse, then x + k·m is also an inverse for any integer k. Calculators typically show the least non-negative residue (0 to m−1), but you can also represent it in a symmetric range.

Modular division by a means multiplying by a⁻¹ (mod m). For example, b ÷ a (mod m) is b×a⁻¹ (mod m) if the inverse exists.

Yes. Modular inverses are used in RSA key math, elliptic curve cryptography, and many number-theory based protocols. They are also common in coding theory and algorithms.

Modulo 1, every number is congruent to 0, so you cannot satisfy a×x ≡ 1 (mod 1). The calculator will report that no inverse exists.

Yes. It uses BigInt-based arithmetic in the browser, which is designed for integer calculations beyond standard floating-point limits.

Results are for education and planning. Always verify inputs (especially modulus and gcd condition) before using modular inverses in proofs, exams, or security-sensitive contexts.