Modulo Calculator

Find the remainder of a division — a mod n. Enter a value and a modulus to get the modulo result and the quotient, with negative numbers handled correctly.

a mod n 0
Quotient (⌊a ÷ n⌋) 0
Truncated remainder (a % n) 0

What modulo means

Modulo is the remainder left after dividing. The result of a mod n is whatever is left over when a is divided by n:

a mod n = a − n × ⌊a ÷ n⌋

So 17 mod 5 = 2, because 5 goes into 17 three times (15) with 2 left over. The long division calculator shows the quotient and remainder side by side.

Negative numbers

Conventions differ. The mathematical modulo (shown as the main result) always returns a non-negative value for a positive modulus, so −17 mod 5 = 3. Most programming languages use a truncated remainder that keeps the sign of the dividend, giving −2 — shown as the third result for reference.

Where modulo shows up

Frequently asked questions

What is the modulo operation?

Modulo gives the remainder after dividing one number by another. Written "a mod n", it is what is left over when a is divided by n. For example, 17 mod 5 = 2, because 17 divided by 5 is 3 with 2 left over.

How do you calculate a mod n?

Divide a by n, take the whole-number quotient, multiply it back, and subtract: a − (n × quotient). For 17 and 5, the quotient is 3, so 17 − (5 × 3) = 17 − 15 = 2.

How does modulo work with negative numbers?

It depends on the convention. The mathematical modulo always returns a non-negative result with a positive modulus, so −17 mod 5 = 3. Many programming languages instead return a result with the sign of the dividend (−2). This calculator shows the non-negative mathematical result and notes the truncated version.

What is modulo used for?

It is everywhere in computing and math — wrapping clock times (hours mod 12), checking even or odd (n mod 2), cycling through a list, hashing, and cryptography. Anytime something repeats in a cycle, modulo finds the position within that cycle.

What is the difference between modulo and division?

Division tells you how many whole times one number fits into another (the quotient); modulo tells you what is left over (the remainder). They are the two halves of the same operation — the long division calculator shows both together.

Disclaimer: Inputs are treated as whole numbers; a modulus of zero is undefined. Provided for educational purposes.