Advanced

Modular Exponentiation Calculator

Compute (base^exponent) mod m quickly and exactly using binary exponentiation by squaring.
Integer base
Non-negative integer
Positive integer
Result: (base^exponent) mod m
9

Computed with exponentiation by squaring

Base
7
Exponent
256
Modulus
13
Result
9
01.63.34.96.58.19.811.413Result lands within [0, m)
Results are estimates for general information only and are not professional advice — always verify important results independently before relying on them. Read the full disclaimer.
Quick answer

How does this calculator work?

Modular exponentiation finds (base^exponent) mod m. Instead of computing the huge power directly, it uses binary exponentiation by squaring: square the base and halve the exponent each step, multiplying into the result on set bits, reducing mod m throughout. This runs in about log2(exponent) multiplications and stays exact with big integers.

Formula
result = (base^exponent) mod m, via squaring: while e > 0, if e is odd result = result·b mod m, then b = b·b mod m, e = e >> 1
How this is calculated

Enter three integers: the base b, a non-negative exponent e, and a positive modulus m. The calculator returns the remainder of b raised to e when divided by m. Naively computing b^e first would overflow for large exponents, so this tool uses exponentiation by squaring (also called binary exponentiation).

The algorithm starts with result = 1 and reduces the base modulo m. It then walks through the bits of the exponent from least to most significant: whenever the current bit is 1 it multiplies the running result by the current base (mod m), and on every step it squares the base (mod m) and shifts the exponent right by one bit. Because every intermediate product is reduced modulo m, the numbers stay small and the work is proportional to log2(e) multiplications instead of e of them. All arithmetic is performed with JavaScript BigInt so results are exact regardless of size.

Assumptions and edge cases: the exponent must be a whole number e >= 0 and the modulus must be a positive integer m > 0 (mod 0 is undefined). The base may be negative; it is first normalized into the range 0..m-1 using ((b mod m) + m) mod m, so the returned remainder is always non-negative. When e = 0 the result is 1 mod m. When m = 1 the result is always 0.

Frequently asked questions

For large exponents b^e is astronomically big and slow or impossible to store. Reducing modulo m at every multiplication keeps every value below m and finishes in about log2(e) steps.

Yes. The base is normalized into 0..m-1 before the loop using ((b mod m) + m) mod m, so a negative base still yields a correct non-negative remainder.

By convention b^0 = 1, so the result is 1 mod m (which is 0 when m = 1).

Also known as

power mod calculator
modpow
a^b mod m
fast exponentiation
mod power

APA

TG we-Calculate Editorial Team. (2026). Modular Exponentiation Calculator [Online calculator]. TG we-Calculate. https://we-calculate.com/calculator/modular-exponentiation-calculator

Chicago

TG we-Calculate Editorial Team. "Modular Exponentiation Calculator." TG we-Calculate. 2026. https://we-calculate.com/calculator/modular-exponentiation-calculator.

IEEE

TG we-Calculate Editorial Team, "Modular Exponentiation Calculator," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/calculator/modular-exponentiation-calculator

BibTeX

@misc{wecalculate_modular_exponentiation_calculator, title = {Modular Exponentiation Calculator}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/calculator/modular-exponentiation-calculator}}, year = {2026}, note = {TG we-Calculate} }

Did this calculator help you?