Modular Exponentiation Calculator
Inputs
- Write the exponent in binary: 222 = 128 + 64 + 16 + 8 + 4 + 2, which has 8 bits, so the binary method needs 7 squarings instead of 221 multiplications.
- Squaring chain, reducing mod 11 at every step: 7, 5, 3, 9, 4, 5, 3, 9.
- Multiply the residues where the binary expansion has a 1 bit: 5 x 3 x 9 x 4 x 3 x 9, reducing mod 11 as you go.
- The final residue is 5: 7 ^ 222 mod 11 = 5, and every intermediate value stayed below the square of the modulus.
This modular exponentiation calculator computes base^exponent mod modulus and gives you the final remainder. Modular exponentiation never forms the full power; instead it uses repeated squaring and reduces at every step, so the numbers stay manageable. For example, 7^222 mod 11 takes 7 squarings and returns 5. Because every intermediate stays below the square of the modulus, 2^1000 mod 999 = 160 is computed with numbers under a million. The page's worked examples also include 123^456 mod 100 = 61.
The binary method is the accepted standard here because it needs only one squaring per bit of the exponent, which keeps even very large exponents practical. That is why it is the workhorse inside RSA encryption and Diffie-Hellman key exchange, where exponents run to hundreds of digits and direct exponentiation is impossible. This page shows the formula, step-by-step workings, worked examples and sources, so you can follow each squaring and reduction rather than just accept the result.
Worked examples
7^222 mod 11
(7 · 222 · 11)
| Result | 7 ^ 222 mod 11 = 5 |
| Base reduced mod m | 7 |
| Squarings needed | 7 |
| Residues multiplied | 6 |
123^456 mod 100
(123 · 456 · 100)
| Result | 123 ^ 456 mod 100 = 61 |
| Base reduced mod m | 23 |
| Squarings needed | 8 |
| Residues multiplied | 4 |
2^1000 mod 999
(2 · 1000 · 999)
| Result | 2 ^ 1,000 mod 999 = 160 |
| Base reduced mod m | 2 |
| Squarings needed | 9 |
| Residues multiplied | 6 |
Why you cannot just compute the power
The power in a modular exponentiation problem looks harmless on paper. A base, a small superscript, a modulus. But the power itself grows at a speed that defeats any ordinary calculator. Consider 2^1000: that single number has hundreds of digits, far more than any display or standard floating-point format can hold. Write it out and you are already past the limits of everyday arithmetic. Real cryptography makes this look modest. In RSA encryption and Diffie-Hellman key exchange, exponents run to hundreds of digits, and direct exponentiation is impossible — not slow, impossible, because the full power would have more digits than there are atoms worth counting.
This is exactly the gap a modular exponentiation calculator is built to close. Modular exponentiation computes base^exponent mod modulus without ever forming the full power, by repeated squaring and reduction at every step. Instead of building 2^1000 and then dividing by 999, the method squares and reduces as it goes, so the numbers never balloon. The binary method needs one squaring per bit of the exponent. For 7^222 mod 11, that means 7 squarings, and the answer is 5 — reached without ever writing down 7^222.
The size control is the whole point. Every intermediate stays below the square of the modulus, so 2^1000 mod 999 = 160 is computed with numbers under a million. Compare that to the actual value of 2^1000, which runs to hundreds of digits. The modulus acts as a ceiling: after each squaring, the result is folded back down modulo m, and the working numbers stay small enough for a machine — or a careful hand — to handle comfortably.
The same pattern holds across every example. 7^222 mod 11 = 5. 123^456 mod 100 = 61. 2^1000 mod 999 = 160. In each case the exponent is large, the true power is astronomically larger, and yet the computation stays inside a modest range because reduction happens at every step rather than at the end. That is why modular exponentiation is the workhorse inside RSA encryption and Diffie-Hellman key exchange, where exponents run to hundreds of digits and direct exponentiation is impossible.
So the next time a problem asks for something like 7^222 mod 11, resist the urge to compute the power first. The power is not just big — it is the wrong object to build. Reduce as you go, square bit by bit, and the arithmetic stays tiny from start to finish.
The binary method step by step
The binary method is the standard way a modular exponentiation calculator avoids ever building a giant power. Instead of multiplying the base by itself exponent times, it writes the exponent in binary and works through the bits one at a time, squaring the current residue and reducing it modulo the modulus at every step. Because each reduction keeps the numbers small, the whole computation stays manageable even when the exponent is enormous.
Take 7^222 mod 11. First write the exponent in binary: 222 = 128 + 64 + 16 + 8 + 4 + 2, so the binary form is 11011110, an 8-bit number. The binary method needs one squaring per bit of the exponent, so this example takes 7 squarings. You start with the base 7, square it and reduce mod 11 at each stage to build the squaring chain, then multiply together only the residues that sit under the 1 bits of the exponent, reducing after each multiplication. Working 7^222 mod 11 through to the end gives 5.
The reason this works is that every intermediate value stays below the square of the modulus. For 7^222 mod 11 the modulus is small, so the residues never grow beyond a handful of values. The same guarantee holds at scale: 2^1000 mod 999 = 160 is computed with numbers under a million, because each step is reduced before the next squaring. That bound is what makes the method practical rather than merely clever.
This is why the binary method is the workhorse inside RSA encryption and Diffie-Hellman key exchange, where exponents run to hundreds of digits and direct exponentiation is impossible. A modular exponentiation calculator applies the same squaring-and-reducing loop, so the arithmetic you can check by hand on small examples is exactly the arithmetic a computer runs on huge ones.
- Write the exponent in binary (222 = 11011110).
- Start with the base and square it once per bit of the exponent, reducing mod the modulus each time.
- Multiply together only the residues under the 1 bits, reducing after each multiplication.
- 7^222 mod 11 takes 7 squarings and returns 5.
| Example | Result |
|---|---|
| 7^222 mod 11 | 5 |
| 123^456 mod 100 | 61 |
| 2^1000 mod 999 | 160 |
Reading the squaring chain
The squaring chain is the calculator's running record of the binary method. Read down the table and each row holds a value obtained by squaring the row above it and reducing the result modulo m. The first row starts with the base itself, reduced mod m. From there, every entry is the previous entry squared mod m, so the chain never grows: each value is a remainder below m. That is the whole trick behind a modular exponentiation calculator — the numbers stay small even when the exponent is enormous, because reduction happens at every step instead of at the end.
The exponent's binary form decides which rows matter. The binary method needs one squaring per bit of the exponent, so an exponent with n bits produces a chain of n squarings. For example, 7^222 mod 11 takes 7 squarings and returns 5. Rows are selected according to the set bits of the exponent, and the selected entries are multiplied together, with a reduction mod m after each multiplication. That product of selected rows, reduced mod m, is the answer shown at the bottom of the table. The unselected rows are still needed — they feed the squaring chain — but they do not enter the final product.
The size of the entries is what makes the chain readable rather than overwhelming. Every intermediate stays below the square of the modulus, so the arithmetic never escapes into huge integers. With 2^1000 mod 999 = 160, all the work is done with numbers under a million, even though 2^1000 written out would have hundreds of digits. When you scan the table, you are seeing exactly those bounded values — each one a remainder, each one small enough to check by hand if you want to.
To read a specific chain, work from the top: confirm the first row is the base reduced mod m, then check that each following row equals the one above squared, mod m. Mark the rows the exponent's binary digits select, multiply them in order with a reduction after each multiplication, and compare your result to the calculator's output. The other worked examples follow the same pattern: 123^456 mod 100 = 61 and 7^222 mod 11 = 5 both come from a chain of squarings plus a product of selected rows. This is the same procedure used inside RSA encryption and Diffie-Hellman key exchange, where exponents run to hundreds of digits and direct exponentiation is impossible — the chain is simply too long to display there, but it is identical in structure.
The chain table is therefore a transparency tool: it lets you audit the calculator's answer step by step instead of trusting a black box.
- First row: the base reduced mod m.
- Each later row: the row above squared, then reduced mod m.
- Selected rows: those matching the set bits of the exponent.
- Answer: the selected rows multiplied together, reduced mod m after each multiplication.
- All entries stay below m squared, so the numbers remain manageable.
Where it is used
Modular exponentiation is not an academic curiosity. It is the arithmetic engine behind most of the public-key cryptography that protects ordinary internet traffic, and understanding where it is used explains why a modular exponentiation calculator matters beyond the classroom.
RSA encryption and signatures rest on it directly. In RSA, a message is raised to a large exponent modulo a large modulus, and the same operation in reverse recovers or verifies the message. The exponents involved run to hundreds of digits, so forming the full power first is impossible — the intermediate number would have more digits than there are atoms in any practical memory. Instead, the binary method performs one squaring per bit of the exponent, reducing modulo the modulus after every step. The same technique appears in Diffie-Hellman key exchange, where two parties each raise a public base to a secret exponent modulo a shared prime, and in ElGamal, whose encryption and signature schemes are built on the same modular-power structure. At survey level, all three schemes share one requirement: a fast, exact way to compute base^exponent mod modulus without ever forming the full power. That is precisely what a modular exponentiation calculator does.
The scale is what makes the algorithm essential. The binary method needs one squaring per bit of the exponent: 7^222 mod 11 takes 7 squarings and returns 5. Every intermediate stays below the square of the modulus, so 2^1000 mod 999 = 160 is computed with numbers under a million. Those examples are small enough to check by hand, but the same repeated squaring and reduction at every step scales to cryptographic sizes, where direct exponentiation is simply out of reach.
The same operation also powers Fermat-style primality checks. Fermat's little theorem says that for a prime p and a base a not divisible by p, a^(p-1) mod p equals 1. Testing that condition means computing a modular power with an exponent nearly as large as the modulus itself — exactly the workload the binary method handles. A result other than 1 proves the number is composite, which is why these checks appear in the routines that generate and validate the large primes used in the schemes above.
In short, whether the goal is encrypting a message, agreeing on a shared secret, signing a document, or screening a candidate prime, the underlying computation is the same: one modular exponentiation, repeated many times.
- RSA encryption and signatures: raise a message to a large exponent modulo a large modulus.
- Diffie-Hellman key exchange: each party raises a public base to a secret exponent modulo a shared prime.
- ElGamal encryption and signatures: built on the same modular-power structure.
- Fermat-style primality checks: test whether a^(p-1) mod p equals 1 to screen out composites.
- Shared requirement: exponents of hundreds of digits, handled by repeated squaring with reduction at every step.
FAQs
How does modular exponentiation work?
Square the base repeatedly, reducing mod m each time, then multiply the residues matching the exponent's 1 bits. For example, 7^222 mod 11 resolves to 5 in 7 squarings. This square-and-multiply approach avoids ever forming the full power, keeping every intermediate result small and manageable throughout the calculation.
Why not compute the power and then take the remainder?
Because the power is astronomically large for real exponents. Reducing at every step keeps every intermediate below m^2 instead, so the numbers stay small enough to handle easily. Computing the full power first would produce numbers far too big to store or work with in practice.
What does 2^1000 mod 999 equal?
160. The calculator's chain never exceeds 999^2 even though the full power 2^1000 has hundreds of digits. By reducing after each squaring and multiplication, the intermediate values stay bounded, so the result is reached without ever writing out that enormous number.
How many multiplications does the method need?
About twice the bit length of the exponent at most: one squaring per bit plus one multiply per 1 bit. So the work grows with the size of the exponent rather than with the size of the full power, which is what makes the method practical for large inputs.
What if the modulus is 1?
Every residue mod 1 is 0, since any integer is divisible by 1. That is a degenerate case the calculator excludes by requiring a modulus of at least 2. With a modulus of 2 or more, the residues are meaningful and the square-and-multiply chain behaves as expected.
Is this how RSA computes?
Yes. RSA encryption and decryption are exactly modular exponentiations with very large operands, performed with the same square-and-multiply idea in big-integer arithmetic. The same repeated squaring and selective multiplication, with reduction at each step, underlies the modular exponentiation at the heart of RSA.