Modular Exponentiation Calculator
Compute base^exp mod m.
Result
How it is calculated
The tool computes baseexp mod m, the remainder when baseexp is divided by m, with square-and-multiply. It walks through the binary digits of the exponent: the running base is squared each time (taking the remainder after every squaring), and it is multiplied into the result whenever the current binary digit is 1. This keeps every intermediate number below m2, so enormous powers never have to be written out. All inputs are cut to whole numbers, the modulus must be at least 1, and the exponent cannot be negative. A negative base is first brought into the range 0 to m−1.
Worked example
Find 7128 mod 13. Square repeatedly, reducing mod 13 each time: 72 = 49 → 10; 74 = 100 → 9; 78 = 81 → 3; 716 = 9 → 9; and so on. Since 128 is a power of two, no extra multiplications are needed beyond the final squaring chain. The remainder is 3, without ever computing the 109-digit number 7128.
Common mistakes
- Computing the full power first and then taking the remainder; with large exponents the number overflows or loses precision.
- Entering a negative exponent; a modular inverse is a different operation and the tool returns no result.
- Using a modulus of 0 or less; division by zero has no remainder.
- Expecting a decimal base or exponent to be honoured; they are truncated to integers.
About this calculator
This calculator computes modular exponentiation — base^exponent mod modulus — using the fast "square-and-multiply" method instead of computing the full power first, which keeps the numbers manageable even for huge exponents.
It's the core operation behind public-key cryptography: RSA encryption, Diffie-Hellman key exchange, and digital signatures all repeatedly raise numbers to large powers modulo a big number. Computer science students use it to learn the algorithm, and developers use it to verify results while implementing crypto code.
Was this helpful?
You can pick up to 3 reactions.
Popular calculators
Loan Calculator
Monthly payment, total interest and full amortization schedule.
Percentage Calculator
Percent change, percent of, and ratio calculations.
Discount Calculator
Calculate final price, savings, and discount amount.
BMI Calculator
Body mass index from height and weight (metric or imperial).
Age Calculator
Compute your exact age in years, months and days from a birth date.
Compound Interest Calculator
Calculate the final amount and interest earned with compounding.
All Calculators
No calculators found
Comments (0)