Modular Exponentiation (a^b mod m) & Modular Inverse Calculator

Evaluate cryptographic modular powers and multiplicative inverses mod m.

Modular Power (a^b mod m) 7
Simple Remainder (a mod m) 7
Multiplicative Inverse a⁻¹ mod m 15
Greatest common divisor gcd(a, m) 1
Inputs
Try:
Base integer a.
Non-negative integer exponent b.
Positive integer modulus m (m ≥ 2).
Results & Graph
Modular Power (a^b mod m)
7
Simple Remainder (a mod m)
7
Multiplicative Inverse a⁻¹ mod m
15
Greatest common divisor gcd(a, m)
1

Modular Power (a^b mod m)

Graph 1 • How the inputs feed Modular Math
Modular Exponentiation (a^b mod m) & Modular Inverse Calculator • Custom Domain Schematic (Number Theory) baseAexponentModular Math Base A: 7 • Exponent B: 13 MODULAR POWER (A^B MOD M) 7 • Simple Remainder (a mo: 7 • Multiplicative Inverse: 15 Eq: R ≡ a^b (mod m); a × a^(−1) ≡ 1
Graph 2 • Modular Power (a^b mod m) as Base A changes (40% to 160% of current)
0 6.16 12.32 2.80 2.80 4.20 4.20 5.60 5.60 7 7 8.40 8.40 9.80 9.80 11.20 11.20
Graph 3 • Base A and Exponent B together Compares Modular Power (a^b mod m) when Exponent B is shifted +25% (solid) vs. −25% (dashed).
0 5.00 10.01 --- Exponent B @ 75% 4.90 -30% 5.95 -15% 7 +0% 8.05 +15% 9.10 +30%
Summary: 7^13 ≡ 7 (mod 26). Multiplicative inverse a⁻¹ ≡ 15 (mod 26).
Summary: 7^13 ≡ 7 (mod 26). Multiplicative inverse a⁻¹ ≡ 15 (mod 26).
Interactive chart & math engine powered by CalculatorGraph

Formula: Modular Math Mathematical Identity

R ≡ ab (mod m)
a × a−1 ≡ 1 (mod m)
R ≡ a^b (mod m); a × a^(−1) ≡ 1 (mod m)
  • baseA: Base A (numeric parameter)
  • exponentB: Exponent B (numeric parameter)
  • modulusM: Modulus M (numeric parameter)

Frequently Asked Questions

Why does the power box keep matching the remainder box?

With the default exponent of 13 and modulus of 26, every base raised to the 13th is congruent to itself mod 26. The modulus is 2 times 13, and Fermat's theorem covers both primes. So the power box always repeats the remainder box. Change the exponent to 2 or 5 to see the power behave independently, or change the modulus to a number such as 25 that is not a product of distinct primes.

Which bases have an inverse mod 26?

Only the odd numbers other than 13, giving 12 of the 26 residues. Those are the bases whose gcd with 26 is 1. Even bases share the factor 2 with 26 and 13 shares the factor 13, so the inverse line shows none for all of them and the gcd line shows the shared factor.

How do I decode a multiply-by-7 cipher with this page?

Enter 7 as the base and 26 as the modulus and read the inverse line, which shows 15. Multiply each encrypted letter number by 15 and take the remainder mod 26. For example, a letter value of 21 times 15 reduces to 3, which recovers the letter that was multiplied by 7 to make 21.

Can I compute a negative power like 3 to the minus 2?

Yes. A negative exponent means a power of the inverse. With base 3, exponent minus 2 and modulus 7, the power line shows 4, because the inverse of 3 is 5 and 5 squared leaves 4 mod 7. If the base shares a factor with the modulus, there is no inverse, and the calculator refuses the negative exponent with a message.

What does the gcd line mean when it shows 13?

It means the base and the modulus share the factor 13. With a modulus of 26 that happens for a base of 13 itself and its odd multiples. A gcd above 1 rules out an inverse, so the inverse line reads none. It also means every power of 13 stays a multiple of 13 mod 26.

How large a modulus can the inverse line handle?

Far more than classroom sizes. The inverse comes from the extended Euclidean algorithm on exact big integers, so moduli in the tens of thousands, or with ten digits, still return an inverse whenever the gcd is 1. The number of steps grows only with the number of digits, not with the size of the modulus itself.

How many squarings does 7 to the 13th need?

Three. Thirteen in binary needs four digits, so you square 7 three times to get the second, fourth and eighth powers mod 26. You then multiply together the eighth, fourth and first powers, which are 3, 9 and 7, and reduce. The answer is 7, the same as the headline.

Does the order of reducing and raising matter?

No, and that is the whole reason modular exponentiation works. You can reduce the base first, reduce after every multiplication, or reduce only at the end, and the remainder is the same. A base of 33 against 26 shows this: it reduces to 7, and its 13th power is 7 too.

Why does a modulus of 1 give a result of 0?

Every integer leaves a remainder of 0 when divided by 1, so every power and every remainder mod 1 is 0. The calculator accepts a modulus of 1 for that reason, but it refuses 0 and negative moduli with a message. A modulus of 1 is rarely useful in practice, so treat it as a curiosity.

Is the power result reliable for very large moduli?

Yes. The engine works with exact big integers, so the multiplications inside square and multiply never lose digits the way ordinary browser numbers do beyond about 16 significant figures. A test with a ten digit prime modulus matched an independent exact calculation. Speed is the only practical limit, and it is fine for anything a student would type.

How can I check the inverse without trusting the tool?

Multiply the base by the claimed inverse and divide by the modulus. The remainder must be 1. For the default, 7 times 15 leaves 1 when divided by 26. If the modulus is prime, you can also raise the base to the modulus minus 2 in the power box and compare.

Four outputs from base 7, exponent 13 and modulus 26

Three boxes drive everything here. The defaults are a base of 7, an exponent of 13 and a modulus of 26, and they produce four numbers at once.

The headline, Modular Power, is 7. That is the remainder when 7 raised to the 13th power is divided by 26. Below it, Simple Remainder is also 7, because 7 is already smaller than 26 and needs no reducing. The Multiplicative Inverse line shows 15. The coprime check, which is the greatest common divisor of the base and the modulus, shows 1.

Those four lines answer different questions. The power is what you need for repeated multiplication, such as a step in a textbook RSA example or a check on a cyclic pattern. The remainder tells you which residue class the base belongs to. The inverse is the number that undoes multiplication by the base. The gcd tells you whether that inverse can exist at all.

The modulus 26 is not a random choice. It is the size of the English alphabet, which is why this default appears so often in classroom cipher exercises. A multiply-by-7 letter shift uses exactly the inverse shown here to decode, so the default doubles as a small cryptography lesson.

Why an exponent of 13 against 26 always hands back the base

Try a few bases with the default exponent and modulus. A base of 7 gives a power of 7. A base of 11 gives 11. A base of 4 gives 4. Run a base of 2 and the power is 2. Even a base of 33 returns 7, which is just 33 reduced mod 26. It is not a coincidence.

The modulus 26 is 2 times 13, and both of those are prime. Fermat's little theorem says any number raised to the 13th power leaves the same remainder mod 13 as the number itself. Mod 2 the same is true of any power at all. Put the two together and every base raised to the 13th power is congruent to itself mod 26.

There is a second way to see it for bases that share no factor with 26. Only 12 numbers below 26 are coprime to it, and Euler's theorem says each of them raised to the 12th power is 1 mod 26. Running a base of 7 with an exponent of 12 confirms it: the power line reads 1. One more multiplication by 7 then lands back on 7.

For anyone exploring the tool, this means the default exponent is a poor demonstration of how powers scramble numbers. Change the exponent to something like 2, 5 or 12 and the power box starts to move independently of the remainder box.

Checking the inverse of 15 by hand

The inverse line claims that 15 undoes multiplication by 7 mod 26. That is easy to test. Seven times 15 is one more than four times 26, so the product leaves a remainder of 1. That is the definition of an inverse.

A base of 11 works the same way. It shows an inverse of 19, and 11 times 19 is one more than eight times 26. A base of 5 against 26 gives 21, and a base of 3 gives 9, which you can confirm because 27 is one more than 26.

In a cipher exercise, that inverse is the decoding key. If each letter number was multiplied by 7 mod 26 to encrypt it, multiplying the result by 15 mod 26 brings back the original. Try it with the letter value 3: 3 times 7 is 21, and 21 times 15 reduces to 3 again.

The engine finds the inverse with the extended Euclidean algorithm, the same method you would use on paper: divide repeatedly, keep track of the remainders, then work back up to write 1 as a combination of the base and the modulus. For a modulus as small as 26 you can also find it by trial, testing multipliers until the product leaves 1, and both routes give 15.

When the inverse line says none and the gcd is above 1

Set the base to 4 and the inverse line reads "none (a and m share a factor)" while the gcd line shows 2. The sentence under the result spells it out: no multiplicative inverse exists, because the gcd is 2 rather than 1.

That is not a limitation of the tool. No residue mod 26 can undo multiplication by 4. Any multiple of 4 is even, and every even number leaves an even remainder when divided by 26, so a product of 4 and anything can never leave 1.

The same thing happens for every even base and for 13. A base of 13 gives a gcd of 13 and again no inverse. A base of 26 gives a remainder of 0, a power of 0 and a gcd of 26.

This is why only 12 of the 26 possible multipliers work in a multiply-only letter cipher. The odd numbers other than 13 all have a gcd of 1 with 26, and only those can be undone. If you are designing an exercise, read the gcd line first. A 1 there means the inverse box holds a real key.

Square and multiply on 7 to the 13th, step by step

The engine uses the fast binary method, also called square and multiply, rather than computing 7 to the 13th in full. You can follow the same steps on paper.

Write 13 in binary as 8 plus 4 plus 1. Then build the powers of 7 by squaring and reducing mod 26 each time. Seven squared is 49, which reduces to 23. Twenty three squared reduces to 9, which is 7 to the fourth. Nine squared is 81, which reduces to 3, and that is 7 to the eighth.

Now multiply the pieces the binary digits select: 7 to the eighth, 7 to the fourth and 7 itself, so 3 times 9 times 7. That product reduces to 7 mod 26, matching the headline.

The point of the method is that no intermediate number ever needs to be bigger than the modulus squared. Even a huge exponent takes only a few dozen squarings. That is what makes the calculation practical for big exponents, and it is exactly how you would check a homework answer without a calculator that can hold enormous integers.

Whole numbers only, negative exponents and a modulus of 1

All three boxes take whole numbers only. Type 4.2 as the base or 2.9 as the exponent and the calculator stops with a message saying base, exponent and modulus must be whole numbers. Number theory works on integers, so round deliberately before you enter anything.

A negative base is allowed and is reduced into the range 0 to m minus 1 first. A base of minus 3 against a modulus of 7 has a remainder of 4, and with an exponent of 5 the power comes out as 2. The sentence under the result writes it as (-3)^5, with brackets, so it is clear the minus sign belongs to the base.

A negative exponent is also allowed, and it means a power of the inverse. With base 3, exponent minus 2 and modulus 7, the power line shows 4. You can confirm it: the inverse of 3 mod 7 is 5, and 5 squared is 25, which leaves 4. An exponent of minus 1 simply returns the inverse, so base 7, exponent minus 1 and modulus 26 gives 15. If the base has no inverse, as with 4 mod 26, a negative exponent is refused with a message giving the gcd.

The modulus must be 1 or more. A modulus of 0 or a negative modulus is refused. A modulus of 1 is accepted and every power and remainder comes out as 0, because every integer leaves remainder 0 when divided by 1.

Large moduli handled with exact integer arithmetic

Ordinary browser numbers are only exact to about 16 significant digits, and modular exponentiation multiplies two remainders together before reducing. With a nine or ten digit modulus those products would pass that limit and quietly go wrong.

This calculator avoids the problem by doing the arithmetic with exact big integers. A test with a five digit base, a five digit exponent and a ten digit prime modulus gave the same power as an independent exact calculation, and its inverse line showed a nine digit inverse that checks out.

The inverse search scales the same way. Because it uses the extended Euclidean algorithm rather than trying multipliers one by one, a modulus in the tens of thousands or far beyond still returns an inverse whenever the gcd line shows 1.

Exact arithmetic does not make the page a cryptography tool. Real keys use moduli hundreds of digits long, generated with secure random numbers and careful padding. Use this page to learn and to check classroom work, never to create or test actual keys.

Using Fermat to cross-check an inverse mod a prime

When the modulus is prime, there is a neat way to check the inverse box using the power box. Raise the base to the modulus minus 2. The result should equal the inverse.

Take a base of 5 and a modulus of 97, which is prime. The inverse line shows 39. Now set the exponent to 95, two less than the modulus. The power line also reads 39. Set the exponent to 96 instead and the power becomes 1, which is Fermat's little theorem in action.

The same check works on a modulus of 13 with the default base. With base 7, modulus 13 and exponent 11, the power should match the inverse line, which reads 2. Seven times 2 is 14, one more than 13, so the inverse is right.

This trick fails for a composite modulus like 26, because Fermat's theorem needs a prime. There you would use Euler's version, raising the base to one less than the count of coprime residues. For 26 that count is 12, so 7 to the 11th mod 26 should equal 15. Running it is a quick way to confirm both the theorem and the tool.