StatGardenREF. DESK
Calculators/Maths/Modular exponentiation
Maths

Modular exponentiation calculator

Computes baseᵉˣᵖ mod m efficiently using square-and-multiply.

What this calculator does

Modular exponentiation works out computes baseᵉˣᵖ mod m efficiently using square-and-multiply. Enter your own figures above and the answer updates as you type: nothing is fixed in the code, so the result reflects exactly the numbers you supply.

The formula this calculator evaluates is printed under the tool and explained below, so you can check the working by hand or reuse it in a spreadsheet.

The formula

FormulaRepeated squaring: result = result × base (mod m) whenever the current exponent bit is 1, halving the exponent each step

The inputs explained

FieldWhat to enter
BaseA number. Starts at 4.
Exponent (non-negative integer)A number. Starts at 13.
ModulusA number. Starts at 497.

Worked examples

Every figure in the tables below is produced by this page’s own calculator at build time, so the numbers and the tool always agree. Select any row to load that scenario.

How the answer changes with base

Every other input is held at the calculator’s starting values while base varies. Select any row to load that scenario into the calculator.

How the answer changes with base
BaseResultBase mod mExpression
22402(2)^13 mod 497
34443(3)^13 mod 497
44454(4)^13 mod 497
62026(6)^13 mod 497
84428(8)^13 mod 497
1227112(12)^13 mod 497