Last verified · v1.0
Calculator · math
Power Modulo Calculator
Compute base^exponent mod modulus instantly. Uses fast modular exponentiation for large values — essential for cryptography, number theory, and RSA calculations.
Inputs
Result (base^exponent mod modulus)
—
Explain my result
Get a plain-English breakdown of your result with practical next steps.
The formula
How the
result is
computed.
What Is Modular Exponentiation?
Modular exponentiation computes the remainder when a base number raised to an exponent is divided by a modulus. The formal notation is ab mod n, where a is the base, b is the exponent, and n is the modulus. This operation appears throughout number theory, computer science, and modern cryptography.
The Formula
The power modulo formula is:
result = baseexponent mod modulus
For a concrete example, compute 34 mod 7: first calculate 34 = 81, then divide 81 by 7 to obtain a remainder of 4. Therefore, 34 mod 7 = 4. The result always falls in the range [0, n-1], regardless of how large the base or exponent becomes.
Understanding the Variables
- Base (a): The number being raised to a power. Accepts any integer, including values larger than the modulus; the calculator reduces it automatically on the first step.
- Exponent (b): A non-negative integer specifying how many times the base multiplies itself. An exponent of 0 always yields 1, since a0 = 1 for any non-zero base.
- Modulus (n): A positive integer that defines the cycle length of the arithmetic system. Every result is an element of the set {0, 1, 2, ..., n-1}.
Fast Modular Exponentiation Algorithm
Computing ab directly for large exponents is computationally infeasible. For instance, 71000 produces a number with over 845 digits — far beyond what any machine can store or multiply conventionally. The fast modular exponentiation algorithm, also called repeated squaring or binary exponentiation, solves this by decomposing the exponent into powers of 2.
The algorithm proceeds as follows:
- Express the exponent in binary form.
- Initialize the result to 1.
- Scan each bit from most significant to least significant: square the current result and reduce modulo n. If the current bit is 1, also multiply by the base and reduce modulo n.
According to Khan Academy's article on fast modular exponentiation, this technique reduces computations that would otherwise require billions of multiplications to just a few dozen operations, making it the indispensable engine behind real-world cryptographic systems. For example, computing 513 mod 23 requires expressing 13 in binary as 1101, which yields at most 2 × log2(13) ≈ 8 multiplications rather than 12 sequential ones.
Why Modular Arithmetic Matters
Modular arithmetic establishes equivalence classes called congruences: two integers a and b are congruent modulo n (written a ≡ b mod n) if they share the same remainder when divided by n. As Gordon College's introduction to number theory explains, this structure underlies clock arithmetic, cyclic groups, and the security guarantees of modern encryption.
Key applications of modular exponentiation include:
- RSA Encryption: Encryption computes c = me mod n; decryption computes m = cd mod n, where e and d are paired public and private keys.
- Diffie-Hellman Key Exchange: Both parties independently compute gx mod p for a shared prime p and generator g, deriving the same secret without ever transmitting it.
- Miller-Rabin Primality Testing: This probabilistic test checks primality by verifying specific modular exponentiation conditions on candidate numbers, powering most real-world prime generation routines.
- Hash Functions and Checksums: Modular reduction produces fixed-size outputs from variable-length inputs, forming the basis of many integrity-verification algorithms.
Worked Examples
Example 1: Basic Calculation
Compute 210 mod 1000: 210 = 1024, and 1024 mod 1000 = 24.
Example 2: Large Exponent via Repeated Squaring
Compute 78 mod 13 step by step: 71 mod 13 = 7; 72 mod 13 = 49 mod 13 = 10; 74 mod 13 = 100 mod 13 = 9; 78 mod 13 = 81 mod 13 = 3. Each step reduces the intermediate value, keeping arithmetic manageable.
Example 3: Simplified RSA
With modulus n = 33 and public exponent e = 7, encrypting message m = 2 gives: c = 27 mod 33 = 128 mod 33 = 29. The recipient reverses this with the private key using the same modular exponentiation operation.
Reference