How to use
Enter the integer base a, a nonnegative integer exponent b, and a positive integer modulus m. The gray example 4, 13, 497 evaluates to 445. Focusing any input clears all three example values before you type, which keeps sample data visually separate from your own values. Negative bases are accepted; negative exponents are not.
Choose Calculate or press Enter to confirm the current expression. Editing any input immediately removes the old remainder and disables Copy, so a result is never presented as belonging to unfinished new input. Clear empties all three controls and does not restore the example. All values are parsed as exact integers rather than floating-point numbers.
Repeated-squaring method
The calculator first normalizes the base into the range 0 through m − 1. It then scans the exponent in binary. At each step, it multiplies the running result by the current factor when the low binary bit is 1, squares the factor, and reduces modulo m. The exponent is divided by two between steps. This is often called binary exponentiation or square-and-multiply.
Reduction happens after every multiplication, so the implementation never constructs the usually enormous integer a^b. The number of loop steps grows with the number of binary digits in b rather than with b itself. Exact BigInt multiplication and remainder operations avoid floating-point precision loss.
Reading the result
Remainder is the standard nonnegative representative of a^b modulo m. Normalized base shows a mod m before exponentiation, which is especially useful for a negative or oversized base. Repeated-squaring steps reports the number of processed exponent bits; it is an implementation trace, not the numeric exponent itself.
For small safe examples, Verification also computes the direct integer power and compares its remainder. For larger exponents it reports verification by repeated squaring, because forming the direct power would defeat the purpose of the algorithm. The calculation still uses exact modular identities at every step.
Worked examples
For 4^13 mod 497, binary exponentiation returns 445. A direct small-power check agrees because 4^13 = 67,108,864 and that integer leaves remainder 445 on division by 497.
For (−2)^5 mod 7, the normalized base is 5 and the standard remainder is 3. For any positive modulus, a^0 mod m starts from 1 mod m. Therefore 99^0 mod 13 is 1, while 99^0 mod 1 is 0. The modulus-one boundary is not treated as an error.
Limits and troubleshooting
The exponent must be at least zero and the modulus must be greater than zero. Modulo zero and negative moduli are rejected by this page. Each base and modulus may contain up to 1,000 significant decimal digits; the exponent may contain up to 500. These explicit limits keep browser work bounded while still supporting values far beyond ordinary number precision.
Enter plain base-10 integers without commas, spaces inside a number, decimal points, scientific notation, fractions, or expressions. A minus sign is allowed only on the base. This tool does not compute a modular inverse for negative exponents. Use a dedicated inverse calculator and verify the required coprimality condition for that separate problem.
Appropriate use and security boundary
Modular powers appear in number theory exercises, primality-related algorithms, cyclic patterns, and cryptographic protocols. This page is suitable for transparent arithmetic checks and classroom examples. It is not a cryptographic library: it provides no constant-time guarantee, key generation, randomness, padding, protocol validation, or protection against side channels. Do not use the browser result alone to design or certify a security system.
Copy result contains the expression, remainder, normalized base, step count, and verification text. Preserve the modulus with the copied remainder, because a bare number does not identify its congruence class. When comparing with another tool, check that both use a nonnegative remainder convention for negative bases.
FAQ
Why is a negative-base result positive?
The tool returns the standard representative from 0 through m−1.
Is exponent zero allowed?
Yes. The result is 1 mod m, including 0 when m=1.
Can I use a negative exponent?
No. That requires a modular inverse and applicable coprimality.
Does it calculate the full power?
No. It reduces after each multiplication.
Is it safe for cryptographic keys?
It is an educational arithmetic tool, not a hardened cryptographic implementation.