Modular Exponentiation Calculator
Calculate a large integer power modulo another integer efficiently with the fast square-and-multiply algorithm.
About modular exponentiation
Modular exponentiation examples
These examples range from a small arithmetic check to common number-theory patterns.
| Expression | Result | Context |
|---|---|---|
| 3^4 mod 5 | 1 | 81 leaves remainder 1 when divided by 5 |
| 7^10 mod 13 | 4 | A compact cryptographic-style example |
| 123^456 mod 789 | 699 | Fast exponentiation avoids creating the full power |
| 2^16 mod 17 | 1 | An example of Fermat's little theorem |
How to calculate a power modulo
- Enter the integer base, which may be positive, zero, or negative.
- Enter a nonnegative whole-number exponent.
- Enter a whole-number modulus greater than one.
- Select Calculate to get the exact remainder and the fast-algorithm operation count.
Modular exponentiation FAQ
Why not calculate the full power first?
The full power can contain millions of digits and waste both time and memory. Reducing after every multiplication gives the same final remainder while keeping intermediate integers manageable.
What is the square-and-multiply algorithm?
It reads the exponent through its binary digits and repeatedly squares the current base residue. Only factors corresponding to one bits are multiplied into the result.
Can the base be negative?
Yes, the calculator normalizes a negative base to its equivalent nonnegative residue modulo m. The final result is always between zero and m - 1.
What happens when the exponent is zero?
Any nonzero base raised to the zero power is one, and the modular result is 1 mod m. The calculator follows the same convention for a zero base with exponent zero.
Can this calculator handle cryptographic-size integers?
It uses arbitrary-size integer arithmetic, so input is not limited to ordinary floating-point precision. Very large exponents still require more work, but binary exponentiation keeps the number of stages logarithmic.