Power Modulo Calculator — aⁿ mod m

Compute aⁿ mod m using modular exponentiation. See the result, step-by-step binary exponentiation, repeated squaring table, and binary decomposition of the exponent.

Result
3.00
3^13 mod 7 = 3
Exponent in Binary
1101
13 in base 2 (4 bits)
Number of Bits
4
Length of the binary representation of n
Multiplications
3
Number of multiply steps (one per '1' bit)
Squarings
3
Number of squaring steps (bits − 1)
Total Operations
6
Total modular multiplications performed
Naive aⁿ
1594323
Full value of aⁿ before mod (shown only for small inputs)

Binary Decomposition of Exponent

1
1
0
1

Blue = 1-bit (multiply), Gray = 0-bit (skip). MSB on left.

Repeated Squaring Steps

Bit #BitBase (before)Result (before)ActionResult (after)Base (after sq.)
01311×3 mod 732
1023skip34
21433×4 mod 752
31255×2 mod 734

Powers of 3 mod 7

k3^(2^k) mod 7Bar
03
12
24
32
Planning notes, formulas, and examples

About the Power Modulo Calculator — aⁿ mod m

Computing large powers modulo a number is fundamental in number theory, cryptography, and competitive programming. Directly calculating aⁿ and then taking the remainder is impractical for large exponents because the intermediate value can be astronomically large. Modular exponentiation solves this efficiently by applying the modulus at every multiplication step, keeping numbers small throughout. The standard algorithm — variously called binary exponentiation, exponentiation by squaring, or the square-and-multiply method — decomposes the exponent n into its binary representation and processes each bit in turn. This Power Modulo Calculator lets you enter any base a, exponent n, and modulus m, then displays the result along with a full breakdown of the binary exponentiation process. A step-by-step table shows the repeated-squaring values and which bits trigger a multiplication into the accumulator. A binary decomposition visual highlights each bit of the exponent. Eight presets cover classic examples including small demonstrations and realistic cryptographic-scale scenarios. Whether you are studying for a number theory exam, implementing RSA, or debugging a competitive-programming solution, the page keeps the algorithm trace and the final residue together.

When This Page Helps

Power modulo problems are usually about the method as much as the final remainder. This calculator keeps the result next to the exponent's binary form and the repeated-squaring steps so you can see how the modular exponentiation algorithm reached the answer.

That is useful in both math and programming contexts. You can verify a theorem exercise, an RSA-style example, or a competitive-programming implementation without treating the modulus reduction as a black box.

How to Use the Inputs

  1. Enter Base (a) and Exponent (n) in the input fields.
  2. Select the mode, method, or precision options that match your power modulo calculator — aⁿ mod m problem.
  3. Read Result first, then use Exponent in Binary to confirm your setup is correct.
  4. Try a preset such as "2¹⁰ mod 1000" to test a known case quickly.
Formula used
aⁿ mod m via binary exponentiation: write n in binary as bₖbₖ₋₁…b₁b₀. Start with result = 1 and base = a mod m. For each bit from LSB to MSB: if bᵢ = 1 then result = result · base mod m; then base = base² mod m.

Example Calculation

Result: Result shown by the calculator

Using the preset "2¹⁰ mod 1000", the calculator evaluates the power modulo calculator — aⁿ mod m setup, applies the selected algebra rules, and reports Result with supporting checks so you can verify each transformation.

Tips & Best Practices

  • Binary exponentiation runs in O(log n) multiplications — efficient even for exponents with millions of digits.
  • Always reduce the base modulo m before starting to keep intermediate values small.
  • For cryptographic applications like RSA, the modulus m is typically the product of two large primes.
  • If gcd(a, m) = 1, Euler's theorem guarantees aᵠ⁽ᵐ⁾ ≡ 1 (mod m), which can simplify very large exponents.

How This Power Modulo Calculator Works

The calculator reduces the base modulo m, writes the exponent in binary, and then walks through the square-and-multiply process one bit at a time. Each step shows which powers are squared and which ones are multiplied into the accumulator.

Interpreting Results

Start with the final residue, then compare it with the exponent-in-binary view and the repeated-squaring table. Those supporting outputs help confirm that each multiplication and reduction happened at the right step.

Study Strategy

Try one small example manually first, such as 2^10 mod 1000, then compare your bit-by-bit work with the calculator. After that, increase the exponent to see why binary exponentiation scales so much better than naive repeated multiplication.

Sources & Methodology

Last updated:

Frequently Asked Questions

  • Modular exponentiation computes aⁿ mod m efficiently without calculating the full value of aⁿ, by taking the modulus at each step.