Modulus Calculator With Steps

Find a mod n using exact integer arithmetic. The result shows the quotient identity and highlights the difference between Euclidean modulus and signed remainder.

Checked by TheToolNet Editorial Team · Last reviewed: September 27, 2026

Definition
a = nq + r, where 0 ≤ r < |n|

Calculate a Mod n

How to Calculate Modulo Without a Calculator

Divide a by n, choose an integer quotient q, and subtract nq from a. For a positive modulus, adjust q until the remainder is at least zero and smaller than n. For example, 17 mod 5 = 2 because 17 = 5×3 + 2.

When the first number is smaller than the modulus, it is already the remainder: 2 mod 5 = 2, 1 mod 5 = 1, and 4 mod 5 = 4. Also, 3 mod 3 = 0 because 3 divides evenly by 3.

Negative Numbers and Programming

The mathematical Euclidean convention makes the result non-negative. Thus −17 mod 5 = 3 because −17 = 5×(−4) + 3. JavaScript, Java and C-style percent operators use truncating division and may return −2 instead. Python returns 3 for this example. The calculator displays both results to prevent silent sign mistakes.

Modulo Applications

Modular arithmetic appears in clock calculations, rotating array indexes, parity checks, checksums and congruence problems. Two integers are congruent modulo n when their difference is divisible by n.

Related Tools

Use the long division calculator for quotient steps or the GCD and LCM calculator for the Euclidean algorithm.