Modular Exponentiation Definition
Modular exponentiation means computing powers in modular arithmetic. For given integers x (base), y (exponent), and n (modulus), we find c such that:
c = xy mod n, 0 ≤ c < n
This power mod calculator uses the fast binary (square-and-multiply) algorithm, which avoids integer overflow and handles very large exponents efficiently. Under the hood, the exponent is processed bit by bit, so even x1,000,000 mod n is computed almost instantly.
How to Use This Power Mod Calculator
- Enter the base x — any integer (positive, negative, or zero).
- Enter the exponent y — a non-negative integer (≥ 0).
- Enter the modulus n — a positive integer (≥ 1).
- Click Calculate (or pick a quick example below the form).
- The result c = xy mod n appears instantly, along with any relevant mathematical insight.
Use the quick examples on the left to walk through the step-by-step cases described below, or save your result with the Share button to send the link to a friend.
Examples of Exponentiation Modulo
Example 1 — Direct method: 5⁴ mod 3
5⁴ = 625. We need 625 mod 3. Since 624 = 3 × 208 is divisible by 3, we have 625 = 3 × 208 + 1, so 5⁴ mod 3 = 1.
Example 2 — Smart method: 5⁴⁴ mod 2
Any power of 5 ends in the digit 5, which is odd, so it is 1 mod 2. Therefore 5⁴⁴ mod 2 = 1 — no need to compute 5⁴⁴ itself.
Example 3 — Last digit: 5⁴⁴⁴ mod 10
Computing mod 10 gives the last digit of a number. Since every positive integer power of 5 ends in 5, we get 5⁴⁴⁴ mod 10 = 5.
Example 4 — Fermat's little theorem: 162⁶⁰ mod 61
Fermat's little theorem states: if n is prime and gcd(x, n) = 1, then xn−1 ≡ 1 (mod n). Here n = 61 (prime) and gcd(162, 61) = 1, so 16260 mod 61 = 1. The calculator detects this case automatically and shows the theorem note.
Measurement Systems
Modular exponentiation operates on pure integers — there are no physical units involved. The result is valid regardless of whether the numbers represent items, bytes, timestamps, or any other quantity. The algorithm works identically for values expressed in US customary units, metric units, or any other system.
FAQs
What is modular exponentiation?
It is the operation xy mod n: raise x to the power y, then take the remainder when divided by n. Because of how modular arithmetic works, the result is always between 0 and n − 1.
Why is fast modular exponentiation important?
Without a fast algorithm, computing x1000 mod n requires 999 multiplications of potentially huge numbers. The binary method reduces this to about log₂(y) steps — for y = 10⁶ that is roughly 20 multiplications instead of a million.
What is Fermat's little theorem?
If n is a prime number and gcd(x, n) = 1, then xn−1 ≡ 1 (mod n). This theorem is the basis for primality testing, RSA encryption, and many other cryptographic protocols.
Can the base be negative?
Yes. The calculator normalises a negative base before computation: it adds multiples of n until the value is in [0, n − 1], which is the standard convention in modular arithmetic.
Can the exponent be zero?
Yes. By convention, x⁰ = 1 for any x, so x⁰ mod n = 1 mod n. If n = 1, the result is 0.
What is the maximum input size?
When the PHP GMP extension is available (which it is on most servers), there is no practical limit. Without GMP, the calculator uses 64-bit PHP integers, which are reliable for bases and moduli up to about 2 billion.