Math

Modular Arithmetic Calculator

Compute modular addition, multiplication, exponentiation by squaring, the modular inverse by the extended Euclidean algorithm, and solve systems with the Chinese remainder theorem.

Last reviewed by the Radiatus Cloud team

Result appears here.

Need this done properly for your business?

Radiatus delivers secure cloud, DevOps & compliance engineering.

Book a free consult

Arithmetic that wraps around

Modular arithmetic is clock arithmetic: everything is reduced to a remainder after division. It is the arithmetic underneath every hash table, checksum, cyclic buffer and public key cryptosystem, because it turns unbounded numbers into a fixed finite set while preserving addition and multiplication. RSA is exactly modular exponentiation with a large modulus, and its security rests on the fact that reversing it requires factoring that modulus.

Not every number has an inverse

Division does not exist in modular arithmetic; multiplying by an inverse replaces it. A number has an inverse modulo m exactly when it shares no factor with m, and the extended Euclidean algorithm finds it in a few steps. When the greatest common divisor is not 1 there is no inverse at all, which is why cryptographic key generation checks this condition and why a modulus that is prime is convenient: every non-zero value then has an inverse.

Exponentiation must be done by squaring

Computing a power by repeated multiplication takes as many steps as the exponent, which is hopeless for the exponents used in cryptography. Exponentiation by squaring reduces it to the number of bits in the exponent, so a 2048 bit exponent takes a few thousand multiplications rather than more than there are atoms in the universe. Reducing modulo m at every step also keeps every intermediate value small, which is what makes the whole thing practical.

Related tools

  • Percentage Calculator — Calculate percentages, percentage change, increase and decrease, and reverse percentages, with the working shown for each result.
  • Statistical Calculator — Calculate mean, median, mode, standard deviation, and more.
  • Probability Calculator — Calculate probabilities for single and combined events, including conditional probability and Bayes' theorem.
  • Scientific Calculator — Perform advanced mathematical operations including trig, log, and exponents.

Frequently Asked Questions

When does a modular inverse exist?

Exactly when the number and the modulus share no common factor, meaning their greatest common divisor is 1. If the modulus is prime, every non-zero value has an inverse, which is one reason prime moduli are so convenient.

What is the extended Euclidean algorithm?

A version of the standard greatest common divisor algorithm that also tracks how to express that divisor as a combination of the two inputs. When the divisor is 1, that combination gives the modular inverse directly.

Why is exponentiation by squaring necessary?

Because repeated multiplication takes as many steps as the exponent. Squaring reduces it to the number of bits, turning an impossible computation into a few thousand multiplications, which is what makes public key cryptography feasible at all.

What is the Chinese remainder theorem?

A method for finding a single number that leaves specified remainders under several pairwise coprime moduli. It guarantees exactly one solution below the product of the moduli, and it is used to speed up RSA decryption by around four times.

Why can results differ from my programming language?

Because many languages define the remainder operator to take the sign of the dividend, so a negative input gives a negative result. Mathematical convention keeps the result in the range 0 to m−1, which is what is used here.

Privacy & Security

Everything runs in your browser; nothing is uploaded.

Data: None
Client-side-Side
Active
v1.0

How to Use

Enter values and a modulus to compute modular arithmetic including inverses and large powers.

Disclaimer: This tool is provided "as is" without warranty of any kind. Results are for educational and utility purposes.