Modular Exponentiation Calculator

Compute b^e mod m quickly with square-and-multiply, even for huge exponents, and see each squaring step. Square-and-multiply uses b^e = ∏ b^(2^i) over the 1 bits of e, reducing mod m at every step so intermediate values stay small. Example: with base b 4, …, the result is 4^13 mod 497 = 445.

Last updated · By · Runs in your browser, nothing is uploaded

Result

Step-by-Step Solution

Enter your values above to see the full working.

How do you use the Modular Exponentiation Calculator?

Enter the base, the exponent and the modulus. The calculator writes the exponent in binary, squares the base repeatedly reducing mod m each time, and multiplies together the squares selected by the 1 bits. The numbers never grow larger than m².

What formula does the Modular Exponentiation Calculator use?

Square-and-multiply uses b^e = ∏ b^(2^i) over the 1 bits of e, reducing mod m at every step so intermediate values stay small. The cost is about log₂(e) multiplications instead of e, which is what makes cryptographic exponents with hundreds of digits practical.

Worked example: Base b 4, Exponent e 13, Modulus m 497

For 4¹³ mod 497, 13 = 1101₂. The squares are 4, 16, 256 and 256² mod 497 = 429, and multiplying those for bits 1, 4 and 8 gives 4 × 256 × 429 mod 497 = 445. So 4¹³ ≡ 445 (mod 497).

With the default values the calculator returns 4^13 mod 497 = 445; Exponent in binary = 1101; Squarings needed = 3.

Where Is This Calculation Used?

Modular exponentiation is the core operation in RSA encryption and decryption, Diffie–Hellman key exchange and primality tests such as Miller–Rabin. It also solves puzzles like “what are the last two digits of 7¹⁰⁰?” (answer: 01, by computing 7¹⁰⁰ mod 100).

What are the most common mistakes with the Modular Exponentiation Calculator?

  • Computing b^e first and then reducing; the number is far too large.
  • Forgetting to reduce after each multiplication.
  • Using a negative exponent, which needs a modular inverse instead.

What Is the Tested Example for the Default Values?

This example is computed by the same code that powers the calculator above, so you can compare it with your own numbers or a textbook answer.

Input: Base b4
Input: Exponent e13
Input: Modulus m497
4^13 mod 497445
Exponent in binary1101
Squarings needed3

Where Can You Verify These Formulas?

The definitions and formulas on this page follow standard references. Check them against these sources:

Built and maintained by S. Dilshan. Found a mistake? Email [email protected] with the page address.

Frequently Asked Questions

How do you calculate a large power modulo m?

Use square-and-multiply: write the exponent in binary, square repeatedly and reduce mod m, multiplying in the squares for each 1 bit.

How can I find the last digits of a large power?

Compute the power modulo 10, 100 or 1000. The last two digits of 7¹⁰⁰ are 7¹⁰⁰ mod 100 = 1.

What is Fermat’s little theorem?

For prime p and a not divisible by p, a^(p−1) ≡ 1 (mod p), which lets you shrink large exponents.