dash–calculator

04 Numbers and Counting

Modular Inverse Table for Moduli 2 to 26

Readout 04-0530 · Updated · Standard formula, shown below

a·x mod m 1
Number a
7
Input
Candidate inverse x
15
Input
Modulus m
26
Input
You enter
Number a, Candidate inverse x, Modulus m
You get
a·x mod m
Rounding
0 dp

This page provides a compact reference for finding the modular inverse of an integer a modulo m, for moduli from 2 through 26. The main table lists the inverse of a for each modulus, or a dash when no inverse exists. A second table focuses on the special case of modulus 26, showing the inverse and the verification that multiplying a by its inverse gives a remainder of 1.

Students learning number theory, cryptography, or discrete mathematics use this table to quickly check results when solving linear congruences or implementing the affine cipher. Instructors often assign exercises with small moduli so that the extended Euclidean algorithm can be practiced by hand, and this table serves as a reliable answer key.

Formula

x is the inverse of a modulo m when a·x ≡ 1 (mod m). It exists exactly when gcd(a, m) = 1, and it is unique in 1 … m − 1. Find it with the extended Euclidean algorithm; for a prime m, also x = am−2 mod m (Fermat). The calculator checks a candidate: the result is 1 when x is the inverse.

Worked Example

Find the inverse of 7 modulo 26. The calculator then checks 7 × 15 mod 26.

Step Working Result
1 26 = 3 × 7 + 5 remainder 5
2 7 = 1 × 5 + 2 remainder 2
3 5 = 2 × 2 + 1 remainder 1
4 back-substitute: 1 = 5 − 2·2 = 3·5 − 7 = 3·26 − 11·7 x = −11
5 −11 mod 26 15
6 check: 7 × 15 = 105 = 4 × 26 + 1 1

Inverse of a modulo m (– = no inverse because gcd(a, m) ≠ 1)

a \ m 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 2 – 3 – 4 – 5 – 6 – 7 – 8 – 9 – 10 – 11 – 12 – 13 –
3 3 2 – 5 3 – 7 4 – 9 5 – 11 6 – 13 7 – 15 8 – 17 9
4 4 – 2 – 7 – 3 – 10 – 4 – 13 – 5 – 16 – 6 – 19 –
5 5 3 5 2 – 9 5 8 3 – 13 7 11 4 – 17 9 14 5 – 21
6 6 – – – 2 – 11 – – – 3 – 16 – – – 4 – 21 –
7 7 4 3 8 7 2 – 13 7 5 13 11 3 – 19 10 7 18 15
8 8 – 7 – 5 – 2 – 15 – 12 – 8 – 3 – 22 –
9 9 5 – 3 11 – 9 2 – 17 9 – 5 18 – 14 3
10 10 – 4 – – – 12 – 2 – 19 – 7 – – –
11 11 6 9 11 3 14 5 7 11 2 – 21 11 16 19
12 12 – – – 10 – 8 – – – 2 – 23 –
13 13 7 5 4 7 3 17 13 17 16 13 2 –
14 14 – 11 – 15 – – – 5 – 9 –
15 15 8 – 14 – – 3 20 – – 7
16 16 – 6 – 4 – 13 – 11 –
17 17 9 13 5 13 19 17 3 23
18 18 – – – 9 – 7 –
19 19 10 7 17 19 4 11
20 20 – 15 – – –
21 21 11 – 6 5
22 22 – 8 –
23 23 12 17
24 24 –
25 25

How to read this table

To find the inverse of a modulo m, locate the row labeled with the value of a and the column labeled with the modulus m. For example, the row for 7 and the column for 26 intersect at the value 15, meaning 7 × 15 ≡ 1 (mod 26). If the cell contains a dash, then no inverse exists because a and m share a common divisor greater than 1.

The second table lists all values of a from 1 to 25 that are invertible modulo 26. For each such a, the table gives its inverse x, the product a·x, and the remainder when that product is divided by 26. For instance, for a = 21, the inverse is 5, and 21 × 5 = 105, which leaves a remainder of 1 upon division by 26.

Notice that the row for a = 1 always contains 1 for every modulus, because 1 × 1 ≡ 1 (mod m).

Inverses modulo 26 with the check a·x

a x = a⁻¹ mod 26 a·x a·x mod 26
1 1 1 1
3 9 27 1
5 21 105 1
7 15 105 1
9 3 27 1
11 19 209 1
15 7 105 1
17 23 391 1
19 11 209 1
21 5 105 1
23 17 391 1
25 25 625 1

Patterns and Properties Visible in the Table

Scanning the table reveals several important patterns. First, a dash appears whenever a and m are not coprime, that is, when their greatest common divisor is greater than 1. Similarly, the row for 3 has dashes when the modulus is a multiple of 3, such as 6, 9, 12, and so on.

Second, for a prime modulus, every nonzero value of a has an inverse. This is visible in the columns for moduli 2, 3, 5, 7, 11, 13, 17, 19, and 23: no dashes appear in those columns (except for a = 0, which is not listed). For composite moduli, only those a that are relatively prime to the modulus appear with a number.

Third, the inverse of a modulo m is unique in the range 1 to m−1. For example, modulo 26, the inverse of 7 is 15, and no other number between 1 and 25 satisfies the congruence. The table also shows that the inverse of 25 modulo 26 is 25 itself, because 25 × 25 = 625, and 625 divided by 26 leaves a remainder of 1.

Finding the Inverse by Hand: The Extended Euclidean Algorithm

When the table does not include a needed modulus or you want to verify a result, the extended Euclidean algorithm is the standard method. The idea is to express the greatest common divisor of a and m as a combination of a and m. If that gcd is 1, the coefficient of a in the combination is the inverse (possibly after adjusting to a positive value).

The worked example on this page illustrates the process for finding the inverse of 7 modulo 26. The steps are:

  • Divide 26 by 7: 26 = 3 × 7 + 5, remainder 5.
  • Divide 7 by 5: 7 = 1 × 5 + 2, remainder 2.
  • Divide 5 by 2: 5 = 2 × 2 + 1, remainder 1.
  • Back-substitute to express 1 as a combination of 26 and 7: 1 = 3 × 26 − 11 × 7.
  • The coefficient of 7 is −11, so the inverse is −11 modulo 26, which equals 15 because −11 + 26 = 15.
  • Check: 7 × 15 = 105, and 105 = 4 × 26 + 1, so the remainder is 1.

This method works for any modulus, not just the ones in the table.

Fermat’s Shortcut for Prime Moduli

When the modulus m is a prime number, there is a faster way to compute the inverse using Fermat’s little theorem. The theorem states that for a prime m and any integer a not divisible by m, a raised to the power m−1 is congruent to 1 modulo m. Dividing both sides by a gives a raised to the power m−2 as the inverse of a modulo m.

For example, if m = 7 and a = 3, then the inverse is 3 raised to the power 5 modulo 7. This method is especially useful when the modulus is large, but for the small moduli in this table, the extended Euclidean algorithm is often quicker by hand.

Note that Fermat’s shortcut applies only when m is prime. For composite moduli like 26, you must use the extended Euclidean algorithm or the table.

Practical Uses: Solving Linear Congruences and the Affine Cipher

Modular inverses are essential for solving linear congruences of the form a·x ≡ b (mod m). If a has an inverse modulo m, multiply both sides by that inverse to isolate x: x ≡ a⁻¹·b (mod m).

In cryptography, the affine cipher uses an encryption function of the form E(x) = (a·x + b) mod 26. Decryption requires the inverse of a modulo 26. The second table on this page lists all possible values of a that are valid for an affine cipher over the English alphabet: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, and 25. For each, the inverse is given, enabling quick decryption.

Classroom exercises often ask students to encrypt a short message using a chosen a and b, then decrypt it using the inverse. The table provides a convenient check for their hand calculations.

Common Mistakes and How to Avoid Them

One common mistake is assuming that every integer has a modular inverse. The inverse exists only when the greatest common divisor of a and m is exactly 1. For example, 2 has no inverse modulo 26 because gcd(2, 26) = 2. The table marks these cases with a dash. Always check the gcd before attempting to find an inverse.

Another error is forgetting to reduce the inverse to the range 1 to m−1. The extended Euclidean algorithm often produces a negative coefficient, as in the worked example where the coefficient was −11. The correct positive inverse is obtained by adding the modulus: −11 + 26 = 15. Similarly, if the coefficient is larger than the modulus, subtract the modulus repeatedly.

When using Fermat’s shortcut, students sometimes apply it to composite moduli. Remember that Fermat’s theorem requires a prime modulus. For composite moduli, use the extended Euclidean algorithm. Finally, when checking the inverse, ensure that the product a·x leaves a remainder of exactly 1 upon division by m. For instance, 7 × 15 = 105, and 105 divided by 26 leaves 1, confirming the inverse.

Limits and Precision of the Table

This table covers moduli from 2 through 26, which is sufficient for many introductory exercises and for the affine cipher with the English alphabet. However, it does not include moduli larger than 26 or negative values of a. For those cases, you must compute the inverse using the extended Euclidean algorithm or another method.

The table also assumes that a is between 1 and m−1. If a is larger than the modulus, reduce it modulo m first.

All entries in the table are exact integers. There is no rounding or approximation. The verification column for modulus 26 shows that each product a·x is a multiple of 26 plus 1, confirming the inverse. For other moduli, you can perform a similar check by multiplying the table value by a and dividing by the modulus.

Frequently Asked Questions

What is a modular inverse?

A modular inverse of a number a modulo m is another number x such that a times x leaves a remainder of 1 when divided by m. For example, 7 times 15 equals 105, and 105 divided by 26 leaves 1, so 15 is the inverse of 7 modulo 26.

Why does an inverse not exist for some numbers?

An inverse exists only when a and m have no common divisor greater than 1, meaning their greatest common divisor is 1. If they share a factor, then any multiple of a will also share that factor, so it can never be congruent to 1 modulo m.

How do I find the inverse using the extended Euclidean algorithm?

Apply the Euclidean algorithm to a and m, then back-substitute to express 1 as a combination of a and m. The coefficient of a is the inverse. For example, for 7 and 26, you get 1 = 3·26 − 11·7, so the inverse is −11, which becomes 15 modulo 26.

Can I use Fermat's little theorem for any modulus?

No. Fermat's little theorem applies only when the modulus is prime. For a prime modulus m, the inverse of a is a raised to the power m−2, reduced modulo m. For composite moduli like 26, you must use the extended Euclidean algorithm or a table.

Why is the inverse modulo 26 important for the affine cipher?

In the affine cipher, encryption uses a multiplier a. To decrypt, you need to multiply by the inverse of a modulo 26. Only values of a that are coprime to 26 have an inverse, so only those can be used. The table lists all valid a values and their inverses.

Calculators that go with this table

Method and sources

Inverses computed exactly with Python’s pow(a, −1, m) (extended Euclid) and checked by a·x mod m = 1.

Source formulas: the standard textbook definitions written out in the Formula section above. Every value in the tables was generated from those formulas in code and spot-checked against the worked example and the calculator on this page; nothing was copied from another table.

Related

Formula used
in a | Number a | - | 7 | 0 | -
in x | Candidate inverse x | - | 15 | 0 | -
in m | Modulus m | - | 26 | 2 | -
out r | a·x mod m | - | a * x - m * floor(a * x / m) | 0

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More on this panel

The whole Numbers and Counting panel →