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
- Loan Calculator
- Profit Calculator
- Discount Calculator
- BMI Calculator
- Percentage Calculator
- Ideal Weight Calculator
- Age Calculator
- Pregnancy Due Date Calculator
- Compound Interest Calculator
- BMR Calculator (Basal Metabolic Rate)
- Tip Calculator
- Fuel Cost Calculator
- Date Difference Calculator
- Sleep Cycle Calculator
- Daily Water Intake Calculator
- Simple Interest Calculator
- Heart Rate Zones Calculator
- Running Pace Calculator
- Pet Age Calculator
- Calories Burned Calculator
- Macro Calculator
- TDEE Calculator (Total Daily Energy Expenditure)
- Waist-to-Hip Ratio Calculator
- Honor Roll Calculator
- One Rep Max (1RM) Calculator
- Ovulation Calculator
- Electricity Cost Calculator
- Unit Price Calculator
- Savings Goal Calculator
- Break-Even Point Calculator
- Paint Calculator
- Course Grade Average Calculator
- Business Days Calculator
- Time Duration Calculator
- Fuel Economy Calculator
- Temperature Converter
- Tile Calculator
- Aspect Ratio Calculator
- Roman Numeral Converter
- Goal Weight Timeline Calculator
- Salary Converter (Hourly to Annual)
- Credit Card Validator (Luhn)
- Body Surface Area (BSA) Calculator
- Feels-Like Temperature Calculator
- Ohm’s Law Calculator
- PPI (Pixel Density) Calculator
- Molar Mass Calculator
- Zodiac Sign Calculator (Western + Chinese)
- IBAN Validator
- Shoe Size Converter
- Country Info & Dialing Code Lookup
- Time Zone Difference (World Clock)
- CAGR (Compound Annual Growth Rate) Calculator
- Rule of 72 Calculator
- Blood Alcohol Content (BAC) Calculator
- Lean Body Mass (LBM) Calculator
- Pythagorean Theorem Calculator
- Speed Converter
- Download Time Calculator
- Date Calculator (Add/Subtract)
No calculators found
Comments (1)
A neat sanity check is Fermat's little theorem: for a prime p and a base not divisible by it, base to the power p - 1 leaves remainder 1. Try 2 to the 10 mod 11 and you get 1. The tool works with exact whole numbers, so large moduli such as 1000000007 are fine; inputs with decimals are cut to whole numbers, and negative exponents get no result. What are you working on, RSA exercises or number theory?