Power Modulo Calculator — bᵉ mod m
Find the remainder of bᵉ divided by m (written bᵉ mod m) quickly and exactly, no matter how large the exponent.
The remainder after dividing bᵉ by m — always in [0, m)
- 1
Full power bᵉ
3 ^ 7 = 2,187 - 2
Full cycles (quotient)
floor(2,187 ÷ 5) = 437 - 3
Remainder bᵉ mod m
2,187 − 437 × 5 = 2
How does this calculator work?
Power modulo computes bᵉ mod m — the remainder of bᵉ divided by m. Instead of computing the huge power first, binary exponentiation squares the base and halves the exponent at each step (reducing mod m throughout), running in about log₂(e) steps with exact BigInt arithmetic.
Formula
How this is calculated
Modular arithmetic asks: after dividing bᵉ by m, what is the remainder? This is written bᵉ mod m and always produces a number in the range 0 to m−1. The operation has a useful "clock" interpretation: numbers wrap around every m steps, so 7 mod 5 = 2 because 7 lands two steps past the 0 mark on a 5-hour clock.
For large exponents, computing bᵉ directly first would produce astronomically large numbers. Instead this calculator uses binary exponentiation (also called exponentiation by squaring): it works through the bits of the exponent from least significant to most, squaring the running base and taking mod m at each step, multiplying into the result only when the current bit is 1. Every intermediate value is bounded by m², so the algorithm is fast regardless of how big e is.
All arithmetic is performed with JavaScript BigInt for exact integer results. A negative base is first normalised into 0..m−1 using ((b mod m) + m) mod m. Constraints: e must be a non-negative integer and m must be a positive integer; fractional inputs are rejected.
Frequently asked questions
For large exponents bᵉ is an astronomically large number — too big to compute or store. Binary exponentiation keeps every value below m² by reducing mod m at every step, finishing in about log₂(e) multiplications instead of e.
"mod m" means the remainder after integer division by m. For example, 17 mod 5 = 2 because 17 = 3 × 5 + 2. The result is always in the range 0 to m−1.
Yes. A negative base is normalised into 0..m−1 before computation using ((b mod m) + m) mod m, so the result is always a non-negative remainder.
Also known as
TG we-Calculate Editorial Team. (2026). Power Modulo Calculator — bᵉ mod m [Online calculator]. TG we-Calculate. https://we-calculate.com/calculator/power-modulo-calculator
TG we-Calculate Editorial Team. "Power Modulo Calculator — bᵉ mod m." TG we-Calculate. 2026. https://we-calculate.com/calculator/power-modulo-calculator.
TG we-Calculate Editorial Team, "Power Modulo Calculator — bᵉ mod m," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/calculator/power-modulo-calculator
@misc{wecalculate_power_modulo_calculator, title = {Power Modulo Calculator — bᵉ mod m}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/calculator/power-modulo-calculator}}, year = {2026}, note = {TG we-Calculate} }
Did this calculator help you?
