Modular Arithmetic Calculator

Compute a mod m and modular addition, subtraction, multiplication and powers, with the congruence shown.

100% FreeNo sign-upPrivate — runs in your browser
—

Result

Result
—
Unreduced value
—
Quotient (mod only)
—
Congruence
—

Copied to clipboard

How to use this tool

1
Enter a, b and the modulus

Enter the first number, the second number (or exponent for powers) and the modulus m.

2
Choose the operation

Pick a plain remainder, or addition, subtraction, multiplication or a power reduced modulo b.

3
Read the result

Read the reduced result, the unreduced value where shown, and the congruence.

4
Check by hand

For a mod b, verify that a = quotient × b + remainder.

Formula & worked example

a mod m = a − m·⌊a/m⌋ (Euclidean form, adjusted so the result is non-negative); (a ∘ b) mod m reduces the operation result modulo m.

17 mod 5 = 2, because 17 = 3 × 5 + 2.

Limitations — read this before you rely on it

Powers use whole-number exponents of 0 or more up to 10000. Very large inputs can lose integer precision in floating-point arithmetic.

Frequently asked questions

It is the remainder when a is divided by m. This calculator uses the Euclidean remainder, which is always between 0 and |m| − 1, even for negative a.

Add first, then take the remainder modulo m. The same idea applies to subtraction and multiplication.

By repeated squaring, which keeps every intermediate value below the modulus instead of computing the huge power first.

It means a and r leave the same remainder on division by b, so they belong to the same residue class.

Division by zero is undefined, so a modulus of zero has no remainder.