Modular Arithmetic Calculator

Calculate the remainder when one integer is divided by another, with support for addition, subtraction, multiplication, and exponentiation mod n.

Share this calculator

Operation

Results

Enter values Enter a valid number for value a.

Also in General

Number Theory

Modular arithmetic calculator: remainders, congruences, and modular operations

A modular arithmetic calculator finds the remainder when one integer is divided by another, and performs addition, subtraction, multiplication, and exponentiation within a modular system. Modular arithmetic is the mathematics of remainders and is fundamental to cryptography, computer science, and number theory.

What modular arithmetic means

In modular arithmetic, two numbers are considered equivalent (congruent) if they have the same remainder when divided by a given modulus. The notation a is congruent to b (mod n) means that a and b differ by a multiple of n. For example, 17 is congruent to 2 (mod 5) because 17 - 2 = 15, which is divisible by 5.

Everyday life uses modular arithmetic more than most people realise. Clock time is modular: 3 hours after 11 o'clock is 2 o'clock, because 11 + 3 = 14, and 14 mod 12 = 2. Days of the week cycle with modulus 7.

a mod n = a - n x floor(a / n)

The modulo operation returns the remainder after dividing a by n.

Modular operations

Addition, subtraction, and multiplication in modular arithmetic follow the rule that you can reduce each operand modulo n before and after the operation: (a + b) mod n = ((a mod n) + (b mod n)) mod n. This makes large computations manageable because intermediate values stay small.

Modular exponentiation computes a^b mod n efficiently using repeated squaring. This operation is at the heart of RSA encryption and the Diffie-Hellman key exchange, where the modulus is typically hundreds of digits long.

Frequently asked questions

What is the difference between mod and remainder?

For positive numbers, the modulo and remainder operations give the same result. For negative numbers, the convention varies by language and context. In mathematics, the modulo result is always non-negative when the modulus is positive.

Why is modular arithmetic used in cryptography?

Modular exponentiation is a one-way function: it is easy to compute a^b mod n, but very hard to reverse the operation and find b given the result, a, and n. This asymmetry is the basis for RSA and other public-key cryptosystems.

Related

More from nearby categories

These related calculators come from the same leaf category, nearby sibling categories, or the same top-level topic.