Skip to main content

Modular Exponentiation Calculator – baseᵉ mod m

Quick answer

Fast power mod m: 2¹⁰ mod 1000 = 24, 3⁴ mod 5 = 1.

  • Square-and-multiply steps shown — the RSA workhorse that never builds huge numbers.

Figures are estimates from this calculator’s standard formula — adjust the inputs in the tool below for your exact number.

How Modular Exponentiation Works

baseᵉ mod m via square-and-multiply: x² mod m repeatedly, multiplying on set bits

Computing baseᵉ mod m by first forming baseᵉ explodes — 2¹⁰⁰⁰ has 302 digits — so the method squares and reduces mod m at every step, keeping numbers small. For 2¹⁰ mod 1000, exponent 10 = 1010₂: start with 2, square to 4, square to 16 and multiply to 32, square to 1024 ≡ 24. The calculator prints the binary expansion of the exponent, each squaring with its reduction, and the multiplications on the 1-bits. 3⁴ mod 5 squares twice: 3² = 9 ≡ 4, then 4² = 16 ≡ 1 — answer 1. Complexity is O(log e) multiplications, which is why RSA’s 65537 = 2¹⁶+1 exponent is chosen sparse: only 17 squarings plus one multiply. Fermat’s little theorem shortcut appears too: a^(p−1) ≡ 1 (mod p), collapsing exponents mod p−1 for prime moduli.

  1. 1

    Enter base, exponent, modulus

    Such as 2, 10, 1000

  2. 2

    Write the exponent in binary

    1010 for 10 guides the operations

  3. 3

    Square and reduce

    Each step mods immediately: 4 → 16 → 256

  4. 4

    Multiply on set bits

    Combine per the binary digits for the final 24

Use Cases

RSA Operations

Encryption mᵉ mod n with e = 65537 takes 17 squarings

Primality Testing

Fermat and Miller-Rabin tests run these powers

Competitive Programming

Compute huge power towers under a modulus

Tips

  • 1

    Reduce after every multiply — numbers stay below m²

  • 2

    Cost scales with log(exponent), not the exponent itself

  • 3

    For prime m, cut the exponent mod m−1 (Fermat)

Common Mistakes

  • Building the full power before reducing — overflow

  • Skipping a reduction between squarings on large inputs

  • Forgetting the final multiply for the low bit

  • Applying Fermat reduction when m is composite

FAQs

What is 2¹⁰ mod 1000?

1024 mod 1000 = 24.

What is 3⁴ mod 5?

1 — square twice: 9 ≡ 4, then 16 ≡ 1.

How big do intermediates get?

Below m² after each reduction — the whole point of the method.

Can I shrink the exponent first?

For prime m: aᵉ ≡ a^(e mod (m−1)) by Fermat’s little theorem.