free tool, no sign-up

Modulo Calculator

Find the remainder when one whole number is divided by another, with the quotient and the equation that checks it.

The number being divided, such as 17 in 17 mod 5

The modulus. It cannot be 0.

Enter a dividend and a divisor to see the remainder.

Enter a dividend and a divisor to see the remainder.

Examples

This modulo calculator is for classwork that asks for a remainder. Enter a dividend and a divisor, the modulus, and the page shows the remainder, the quotient, and the equation a = nq + r with those numbers filled in. 17 mod 5 is 2 because 17 = 5 × 3 + 2. The remainder is never negative: −7 mod 3 is 2, because −7 = 3 × (−3) + 2. A divisor of 0 is rejected, and a decimal is rejected because modulo here is for whole numbers.

The remainder in a = nq + r

Modulo means the remainder. A mod calculator, also called a modulo calculator or a modulus calculator, takes a dividend a and a divisor n and finds whole numbers q and r such that a = nq + r. The quotient q is how many times n fits into a. The remainder r is what is left. r is never negative, and it is always smaller than the absolute value of n. People also call mod the modulo operator or the modulus operator. In a program the symbol is often %. On this page the answer is the remainder.

17 mod 5 is 2, because 5 fits into 17 three times and 2 is left over: 17 = 5×3 + 2. 5 mod 2 is 1, because 5 = 2×2 + 1. 8 mod 4 is 0, because 4 fits exactly twice: 8 = 4×2 + 0. When the remainder is 0, the dividend is divisible by the divisor. The divisor is the modulus, and it cannot be 0, because division by zero has no quotient and no remainder. Modulo here is for whole numbers, so a decimal such as 7.5 is not accepted.

0 mod 2 and 1 mod 2

0 mod 2 is 0. Two goes into zero zero times, and nothing is left: 0 = 2×0 + 0. A whole number is even when its remainder mod 2 is 0, so this is the even-or-odd check.

1 mod 2 is 1. Two is larger than 1, so it fits zero times and the remainder is the dividend itself: 1 = 2×0 + 1. A whole number is odd when its remainder mod 2 is 1. The same pattern holds whenever a positive dividend is smaller than a positive divisor. 3 mod 5 is 3, because 5 fits zero times and all 3 is left over.

A negative dividend keeps a non-negative remainder

The remainder on this page stays from 0 up to one less than the absolute value of the divisor, even when the dividend is negative. The quotient steps down, into the negatives if it has to, so the equation still adds up. −7 mod 3 is 2, because −7 = 3×(−3) + 2. It is not −1.

Some programming languages use a different rule for the modulo operator. In JavaScript the % operator takes the sign of the dividend, so −7 % 3 is −1. That programming remainder still fits an equation, −7 = 3×(−2) + (−1), but the remainder is negative. That is not the school rule, and it is not the result this calculator reports. When the two remainders differ, the page shows the JavaScript value as a labeled side note. The primary answer is the non-negative remainder.

Related calculator

Frequently Asked Questions

What is 17 mod 5?

17 mod 5 is 2. Five fits into 17 three times, because 5×3 = 15, and 17 − 15 = 2. The equation is 17 = 5×3 + 2, so the quotient is 3 and the remainder is 2.

What is 5 mod 2?

5 mod 2 is 1. Two fits into 5 twice, because 2×2 = 4, and 1 is left over. The equation is 5 = 2×2 + 1.

What is 0 mod 2?

0 mod 2 is 0. The equation is 0 = 2×0 + 0. Zero is even, and an even number leaves a remainder of 0 when the modulus is 2.

What is 1 mod 2?

1 mod 2 is 1. Two does not fit into 1 even once, so the quotient is 0 and the remainder is 1. The equation is 1 = 2×0 + 1. One is odd.

Why is −7 mod 3 equal to 2, not −1?

The remainder here is never negative. −3 times 3 is −9, and −9 + 2 = −7, so −7 = 3×(−3) + 2 and the remainder is 2. The quotient is −3. JavaScript's % operator gives −1, because it lets the remainder take the sign of the dividend. That is a different rule. This calculator reports 2.

Related Tools