---
slug: modular-inverse-calculator
title: "Modular Inverse Calculator"
category: math
updated: 2026-11-18
canonical: https://calcseed.com/c/math/modular-inverse-calculator/
html: /c/math/modular-inverse-calculator/
---

# Modular Inverse Calculator

Find the modular multiplicative inverse of a number modulo m.

## Quick answer

**Quick answer:** with the default inputs (3, 11), the modular inverse is **4**. At these inputs: gCD(a, m) = **1**. Change any input to update the result.

## Default calculation

Values computed by this calculator at exactly the default inputs listed below.

### Inputs (defaults)

| Input | Value | Unit |
| --- | --- | --- |
| a | 3 |  |
| m | 11 |  |

### Outputs at these defaults

| Output | Value | Unit |
| --- | --- | --- |
| Modular inverse | 4 |  |
| GCD(a, m) | 1 |  |

## Formula

```text
a × x &equiv; 1 (mod m)
```

## Inputs

| Variable | Type | Unit | Default |
| --- | --- | --- | --- |
| a | number |  | 3 |
| m | number |  | 11 |

## Outputs

| Result | Format |
| --- | --- |
| Modular inverse | primary |
| GCD(a, m) | number |
| Modular inverse | number |

## How it works

### What a modular inverse is

The modular multiplicative inverse of a modulo m is the number x with a × x &equiv; 1 (mod m), meaning a × x leaves remainder 1 when divided by m. It exists only when a and m share no common factor greater than 1. At the defaults a = 3 and m = 11, the calculator returns gcd = 1 and inverse = **4**, because 3 × 4 = 12 = 1 + 1 × 11.

### How the extended Euclidean algorithm finds it

The calculator first runs the Euclidean algorithm to compute gcd(a, m). If that gcd is not 1, no inverse exists and it reports 0 as a signal. If the gcd is 1, the extended version back-substitutes through the division steps to find integers x and y with a&middot;x + m&middot;y = 1, and x reduced modulo m is the inverse. The m&middot;y term always vanishes modulo m, which is exactly why the leftover x works.

Existence depends only on the factors the two numbers share. With a = 3 and m = 11 (a prime), any a from 1 to 10 has an inverse. With m = 9, only values coprime to 9 — 1, 2, 4, 5, 7, 8 — have inverses, while a = 3 or 6 fails because they share the factor 3. There are &phi;(m) invertible residues, so for prime m every nonzero element is invertible, and this fact underpins modular arithmetic being a field in that case.

### Worked example with the default inputs

Euclid on (3, 11): 11 = 3 × 3 + 2, then 3 = 2 × 1 + 1, then 2 = 1 × 2 + 0, so gcd = 1. Back-substitute the last nonzero remainder: 1 = 3 − 1 × 2 = 3 − 1 × (11 − 3 × 3) = 4 × 3 − 1 × 11. So x = 4 and y = −1, and indeed 3 × 4 + 11 × (−1) = 12 − 11 = 1. Reduced modulo 11, the inverse is **4**, verified by 3 × 4 mod 11 = 12 mod 11 = 1.

A brute-force check confirms it: 3 × 1 = 3, 3 × 2 = 6, 3 × 3 = 9, 3 × 4 = 12 &equiv; 1. Brute force works for small m, but for m with 18 digits the extended Euclidean algorithm finishes in a few dozen steps, which is why every crypto library uses Euclid rather than search.

### Sample inverses and failures

| a | m | Inverse | Why |
| --- | --- | --- | --- |
| 3 | 11 | 4 | 3 × 4 = 12 &equiv; 1 (mod 11) |
| 7 | 26 | 15 | 7 × 15 = 105 = 4 × 26 + 1 |
| 5 | 12 | 5 | 5 × 5 = 25 &equiv; 1 (mod 12); a is its own inverse |
| 4 | 8 | None | gcd(4, 8) = 4 > 1 |
| 6 | 9 | None | gcd(6, 9) = 3 > 1 |

The self-inverse row is a useful special case: whenever a² &equiv; 1 (mod m), a is its own inverse. Modulo 12, the residues 1, 5, 7 and 11 are all self-inverse, which is one reason clocks make such a tidy modular arithmetic example.

### Where modular inverses are used

- RSA key generation: the private exponent d is the inverse of the public exponent e modulo &phi;(n). With e = 3 and &phi;(n) = 10, d = 7 because 3 × 7 = 21 &equiv; 1 (mod 10).
- Modular division: computing a ÷ b mod m means multiplying by b^−1 mod m, since m and b rarely allow ordinary division.
- Chinese remainder theorem: reassembling a number from its remainders requires one inverse per modulus pair.
- Competitive programming and hashing: division under a prime modulus in combinatorics answers is always performed through inverses.

#### The Fermat shortcut for prime moduli

When m is prime, Fermat&rsquo;s little theorem gives the inverse as a^m−2 mod m without any back-substitution. For a = 3, m = 11: 3^9 mod 11 = 19,683 mod 11. Since 3^5 = 243 &equiv; 1 (mod 11), 3^9 = 3^5 × 3^4 &equiv; 81 &equiv; 4 (mod 11), matching the Euclidean answer of 4. Fast modular exponentiation makes this route competitive even for cryptographic sizes, and it is the standard method when m is a known prime.

### Common mistakes

- Assuming an inverse always exists: a = 4, m = 8 has gcd 4, and the calculator reports inverse 0. Treat a 0 inverse with a nonzero gcd display as no-inverse-exists, not as a real answer.
- Confusing modular inverse with reciprocal: the inverse of 3 modulo 11 is 4, not 1/3. Fractions have no meaning in modular arithmetic until converted through inverses.
- Reporting a negative intermediate: back-substitution can produce a negative x for some inputs; the correct canonical answer is that value plus m. The calculator normalizes into 0–m−1, but hand work often forgets.
- Using gcd = 1 with composite m carelessly: inverses exist, but Fermat&rsquo;s shortcut does not apply. For composite m you need the full extended Euclidean result or Euler&rsquo;s theorem with &phi;(m).
- Forgetting the check: multiplying back (a × x mod m must be 1) costs two seconds and catches nearly every slip. The default case gives 3 × 4 mod 11 = 1.

### Solving congruences with the inverse

#### Turning a congruence into a one-step solve

The inverse turns any linear congruence into a one-step solve. To find x with 3x &equiv; 5 (mod 11), multiply both sides by 4: x &equiv; 4 × 5 &equiv; 20 &equiv; 9 (mod 11). Check: 3 × 9 = 27 = 2 × 11 + 5. The modulo calculator handles the reduction steps, and the same pattern scales to systems solved by the Chinese remainder theorem.

### How big can m get

Both inputs accept values up to 1,000,000,000, and the Euclidean algorithm needs at most about 5 times the number of decimal digits of m division steps — around 50 at the cap. Inputs are reduced internally, so a = 1,000,000,003 with m = 11 works as smoothly as a = 3, since only a mod m affects the result.

## FAQ

### What is the inverse of 3 modulo 11?

4, because 3 × 4 = 12 and 12 mod 11 = 1. The extended Euclidean algorithm finds it via 4 × 3 − 1 × 11 = 1.

### When does no inverse exist?

When gcd(a, m) > 1. For example a = 4 and m = 8 share the factor 4, so every multiple of 4 mod 8 lands on 0 or 4, never 1.

### Can a be larger than m?

Yes. The algorithm reduces a modulo m internally, so a = 26 with m = 11 behaves exactly like a = 4, which has inverse 3 mod 11.

### Why is this used in cryptography?

RSA private keys are modular inverses: the private exponent d satisfies e × d &equiv; 1 (mod &phi;(n)). With e = 3 and &phi;(n) = 10, the key is d = 7.

### How do I compute an inverse for a prime modulus quickly?

Use Fermat: a^m−2 mod m. For a = 3, m = 11, that is 3^9 mod 11 = 4, matching the Euclidean method.

### What does it mean if the result is 0?

A returned inverse of 0 means either gcd(a, m) > 1 or m = 1, in which case every product is congruent to 0. Check the displayed gcd to tell which case you are in.

### How many inverses exist for a given a and m?

Exactly one in the range 0 to m − 1 when gcd(a, m) = 1. All other solutions are that value plus multiples of m, so modulo 11 the inverse of 3 is 4, 15, 26 and so on, all congruent to 4.

### How fast is the computation?

The Euclidean algorithm takes at most about 5 × (number of digits of m) division steps, so even m near 1,000,000,000 finishes in roughly 50 steps, far faster than testing candidates one by one.

## Method and sources

Methodology: Results follow exact mathematical definitions; the arithmetic is deterministic and can be verified by hand from the steps shown.

Last updated: 2026-11-18.
- Extended Euclidean algorithm for the modular multiplicative inverse.
