Boneyard Tools

Modular Exponentiation Calculator

Raise a number to a power modulo m without overflow. The calculator uses square and multiply on big integers, so even million-digit exponents return in an instant. It also computes modular inverses and the extended GCD.

How to compute a modular power

  1. Pick an operation: power mod m, modular inverse, or GCD.
  2. Enter the base, exponent, and modulus (the modulus must be a positive integer).
  3. Read the result. Use Copy to grab the full value, however large it is.

Examples

Power modulo m

2 ^ 10 mod 1000
24

Modular inverse

3 inverse mod 11
4 (because 3 * 4 = 12 = 1 mod 11)

Large exponent

3 ^ 644 mod 645
36

Frequently asked questions

What is modular exponentiation?

Modular exponentiation computes base raised to an exponent, then takes the remainder modulo m, written base^exponent mod m. It keeps every intermediate value small, so the answer is exact even when base^exponent would be astronomically large.

How is it calculated so quickly?

The calculator uses the square and multiply method (binary exponentiation). It squares the base and reduces modulo m at each step, so the work grows with the number of bits in the exponent rather than its size. A million-bit exponent finishes in well under a second.

Where is modular exponentiation used?

It is the core operation of public-key cryptography. RSA encrypts and decrypts with c = m^e mod n and m = c^d mod n, and Diffie-Hellman key exchange raises a shared base to secret exponents mod a prime. It also appears in primality tests like Fermat and Miller-Rabin, and in hashing.

What is a modular inverse?

The modular inverse of a mod m is the number x in the range 0 to m-1 with a * x = 1 mod m. It only exists when a and m share no common factor (their GCD is 1). RSA uses it to derive the private exponent from the public one.

Can the exponent be negative?

Yes, but only when the base has a modular inverse mod m. A negative exponent a^-n mod m is computed as the inverse of a, raised to the power n. If the base and modulus are not coprime, no inverse exists and the calculator reports an error.

Is there a limit on the size of the numbers?

No practical limit. The engine uses arbitrary-precision integers (BigInt), so you can enter values with hundreds or thousands of digits. Paste large numbers directly into the fields.

Do my numbers get sent to a server?

No. The calculator runs entirely in your browser, so your inputs never leave your device. The optional API is for developers who want to call the same math from their own code.

Related tools