AZ Tools

Modular Exponentiation Calculator (aᵇ mod m)

Everyday

Modular exponentiation computes a raised to the power b, reduced modulo m — the core operation behind RSA, Diffie-Hellman and many other cryptographic and number-theory tasks. Computing a^b first and then taking the remainder is impossible for large exponents, so this tool uses fast binary exponentiation (square-and-multiply), reducing modulo m at every step. All arithmetic uses arbitrary-precision big integers, so the result is exact even when the base, exponent or modulus has hundreds of digits. It also reports the modular multiplicative inverse of the base modulo m (the value x with a·x ≡ 1) whenever the base and modulus are coprime. Everything runs locally in your browser — nothing is uploaded.

a^b mod m
9
Modular inverse of a (mod m)2

How to use

  1. Enter the base (a), the exponent (b) and the modulus (m).
  2. Read a^b mod m, computed exactly even for very large numbers.
  3. Check the modular inverse of the base — shown only when gcd(a, m) = 1.
  4. Try a = 7, b = 256, m = 13 to get 9.

Frequently asked questions

Why not just compute a^b and take the remainder?
For large exponents a^b has astronomically many digits and cannot be formed in practice. Square-and-multiply keeps every intermediate value below m², so it stays fast and exact regardless of the exponent's size.
What is the modular inverse line?
It is the number x such that a·x ≡ 1 (mod m). It exists only when the base and modulus share no common factor (gcd = 1); otherwise the tool shows that no inverse exists. This is the value used when 'dividing' in modular arithmetic.
What does an exponent of 0 give?
a^0 mod m is 1 for any base (and 0 when m = 1). Exponents must be non-negative whole numbers; the base may be negative and is normalised into the range 0…m−1 first.

Related tools