Power Modulo Calculator
Compute xy mod n exactly with fast binary exponentiation, even when the full power would be enormous.
The startup example is valid and ready to export.
Inputs
Required signed integer. Example: 4 or – 17.
Required non-negative integer. Zero is allowed.
Required positive integer. The result is always below n.
Result
Power modulo
445
4^13 mod 497 = 445
Normalized base
4
Exponent bits
1101
Set bits
3
Method
Binary
Enter complete valid integers to calculate a residue.
4 to the power 13 modulo 497 equals 445.
Binary exponentiation steps
Each row processes one binary digit of the exponent, starting with the least significant bit.
| Step | Bit | Exponent before | Running base | Action | Result after | Next base |
|---|---|---|---|---|---|---|
| 1 | 1 | 13 | 4 | Multiply result by running base | 4 | 16 |
| 2 | 0 | 6 | 16 | Keep result unchanged | 4 | 256 |
| 3 | 1 | 3 | 256 | Multiply result by running base | 30 | 429 |
| 4 | 1 | 1 | 429 | Multiply result by running base | 445 | 151 |
The algorithm used 4 squaring steps and 3 multiply steps, so it avoided constructing 4^13 = 67,108,864.
How to use the power modulo calculator
What this calculator does
This calculator finds the least non-negative residue of xy modulo n. In practical terms, it answers: “What remainder is left after x raised to the yth power is divided by n?” It uses binary exponentiation, also called exponentiation by squaring, so it reduces intermediate values modulo n after every multiplication instead of constructing the full power. The output is an exact integer identity for the supplied inputs. It does not test whether n is prime, find modular logarithms, or automatically interpret negative exponents through modular inverses.
When to use it
Use it to check modular-arithmetic exercises, study repeating power cycles, verify small cryptography examples, or compute large powers in programming and number-theory problems. Modular exponentiation is a core operation in public-key systems; the IETF RSA specification shows how exponentiation modulo an integer appears in RSA primitives. This calculator is educational and computational; it is not a substitute for vetted cryptographic software.
How to calculate
- The calculator opens with a complete demonstration: x = 4, y = 13, and n = 497. Its result and Excel workbook are ready immediately.
- Replace x (base), y (exponent), and n (divisor) with your integers. Results update live; no Calculate button is necessary.
- Read Power modulo first, then use the binary form and step table to audit how the result was produced.
- Select Download Excel to export the current inputs, outputs, and every algorithm step to a validated .xlsx workbook.
- Select Reset to clear the demonstration values and calculated state. The Excel button is then disabled until all three required fields contain a complete valid set again.
Input guide
x (base) is a required signed integer. Enter digits with an optional leading plus or minus sign; standard comma grouping such as 1,000 is accepted. A realistic example is – 17. The calculator first converts x to its equivalent residue between 0 and n – 1, so changing x by a multiple of n does not change the final answer. Decimal values, scientific notation, malformed grouping, and unsupported symbols are rejected.
y (exponent) is a required non-negative integer, such as 13. A larger exponent generally adds only about one table row per binary digit, not one row per unit of y. An exponent of zero is valid and returns 1 mod n. Negative exponents are outside this calculator's scope because they require a modular inverse and only exist when the base is invertible modulo n.
n (divisor) is the required positive modulus, such as 497. It sets the residue range: every valid answer satisfies 0 ≤ result < n. A modulus of 1 is allowed and always gives 0. Zero and negative values are invalid. The fixed “mod n” viewpoint is part of the broader system described in the MathWorld overview of modular arithmetic.
Output guide
Power modulo is the exact least non-negative residue. Normalized base is x reduced into the same 0 to n – 1 range. Exponent bits shows y in base 2; Set bits counts the 1 digits that trigger result multiplications. The summary pills show the Residue range, Exponent bits count, Loop steps, and total Modular operations. The step table lists the step number, current bit, exponent before division by two, running base, chosen action, result after the action, and next squared base. The equation line restates the complete congruence, and Method identifies the binary algorithm. These values are exact algorithm checkpoints, not approximations.
Worked example
For the startup values, 13 is 1101 in binary. Start with result = 1 and running base = 4. The first bit is 1, so the result becomes 4; square the base to 16. The next bit is 0, so keep result = 4 and square 16 to 256 modulo 497. The third bit is 1, giving 4 × 256 mod 497 = 30; square 256 to 429 modulo 497. The final bit is 1, giving 30 × 429 mod 497 = 445. Therefore, 413 mod 497 = 445. The complete power is 67,108,864, but the algorithm never needs to hold that growing value.
How binary modular exponentiation works
The method repeatedly inspects whether the remaining exponent is odd. If it is odd, the current running base contributes to the result. The running base is then squared modulo n, and the exponent is divided by two using integer division. Because each pass halves the exponent, the number of iterations is proportional to the number of binary digits in y.
base ← (base × base) mod n
exponent ← floor(exponent ÷ 2)
Interpretation and common mistakes
A small residue does not mean the original power is small; it only identifies its congruence class modulo n. Do not confuse the modulus with a percentage or a decimal divisor. The base may be negative, but the displayed residue remains non-negative. When using the result in security work, remember that real protocols impose many requirements beyond modular exponentiation. For example, NIST's Digital Signature Standard specifies approved signature algorithms and operational constraints rather than treating one arithmetic operation as a complete security design.