Power Mod Calculator

Enter a base (a), exponent (b), and modulus (n) to compute ab mod n — the remainder when a raised to the power b is divided by n. The Power Mod Calculator uses a fast binary exponentiation algorithm to handle large numbers without overflow, returning the modular result along with a step-by-step breakdown.

The base integer. Can be negative or zero.

The exponent — must be a non-negative integer.

The modulus — must be a positive integer greater than zero.

Results

a^b mod n

--

Base mod n (a mod n)

--

Exponent in Binary

--

Binary Steps Required

--

Results Table

Frequently Asked Questions

What is modular exponentiation?

Modular exponentiation (also called powmod) is the calculation of a^b mod n — raising a base integer to a power, then taking the remainder when divided by the modulus. It is widely used in cryptography (e.g. RSA), number theory, and computer science because it keeps numbers manageable even when exponents are very large.

How do I calculate a^b mod n by hand?

One efficient method is the binary (square-and-multiply) algorithm: convert the exponent b to binary, then iterate through each bit from most significant to least. For each bit, square the current result mod n, and if the bit is 1, multiply by a mod n. This avoids computing the enormous intermediate value a^b directly.

Why not just compute a^b and then take mod n?

For large exponents, a^b can be an astronomically large number — impossible to store or compute directly even on modern hardware. The fast modular exponentiation algorithm performs mod n at each step, keeping numbers small throughout and preventing arithmetic overflow.

What is Fermat's little theorem and how does it help?

Fermat's little theorem states that if p is a prime and a is not divisible by p, then a^(p−1) ≡ 1 (mod p). This means you can reduce the exponent b modulo (p−1) before computing a^b mod p, dramatically speeding up calculations when the modulus is prime.

How to solve for the exponent given the base and modulo?

Finding the exponent from the result is called the discrete logarithm problem — given a^b ≡ c (mod n), find b. Unlike modular exponentiation (which is fast), the discrete logarithm is computationally very hard for large n, which is the foundation of many cryptographic systems.

Can the base be negative in modular exponentiation?

Yes, the base can be negative. When a is negative, a mod n is handled by taking the standard mathematical modulo (always a non-negative result less than n). For example, (-3)^2 mod 5 = 9 mod 5 = 4. The exponent and modulus must be non-negative integers.

What are the real-world applications of modular exponentiation?

Modular exponentiation is central to public-key cryptography, including RSA encryption, Diffie-Hellman key exchange, and digital signatures. It is also used in primality testing algorithms (e.g. Miller-Rabin), hash functions, and pseudorandom number generation.

Why is modular exponentiation limited to integers?

The modulo operation is defined for integers — it returns the remainder after integer division. Fractional bases or exponents don't have a meaningful integer remainder, so the operation requires all inputs (base, exponent, and modulus) to be integers. The exponent must also be non-negative for the standard definition.

More Math Tools