CompoundPage

Modulo calculator

100 mod 7 = 2 in the modulo calculator, because 7 goes into 100 fourteen times with 2 left over: 100 = 7 × 14 + 2.

100 mod 72

Modulo, floored Takes the sign of the divisor. Python and Ruby %, Excel and Google Sheets MOD.
2
Remainder, truncated Takes the sign of the dividend. The % operator in C, C++, Java, JavaScript and Go.
2
Euclidean Never negative, whatever the signs.
2
Written out
100 = 7 × 14 + 2

How the Long Division Calculator works

a mod n is the remainder when a is divided by n. Write a = n × q + r, where q is the whole number of times n goes into a and r is what is left over. r is the modulo.

Worked example: 100 mod 7. 7 × 14 = 98 and 100 - 98 = 2, so 100 mod 7 = 2.

For two positive numbers every definition agrees. With a negative number they split, because there are two reasonable choices for q.

Truncated division rounds q toward zero, so r takes the sign of the dividend. For -17 mod 5, q = -3 and r = -17 - 5 × (-3) = -2. This is the % operator in C, C++, Java, JavaScript and Go.

Floored division rounds q down, so r takes the sign of the divisor. For -17 mod 5, q = -4 and r = -17 + 20 = 3. This is % in Python and Ruby, and MOD in Excel and Google Sheets.

Euclidean division keeps r from being negative, whatever the signs. -17 mod 5 is 3 here too; Euclidean and floored part ways only for a negative divisor, where -7 mod -3 is -1 floored and 2 Euclidean.

When truncated and floored disagree, they differ by exactly the divisor: -2 + 5 = 3.

Clock arithmetic is the floored version. 10 hours before 3 o'clock is (3 - 10) mod 12 = -7 mod 12 = 5 o'clock, while the truncated answer, -7, is not a time.

Modulo works on decimals the same way: 5.5 mod 2 = 1.5, since 2 goes into 5.5 twice and 5.5 - 4 = 1.5.

Long Division Calculator FAQ

What does mod mean in math?

a mod n is the remainder after dividing a by n. 17 mod 5 = 2, because 5 × 3 = 15 and 17 - 15 = 2. Two numbers with the same remainder are congruent mod n: 17 and 2 are congruent mod 5.

How do I find a mod n on a calculator without a mod key?

Divide, round the quotient down to a whole number, multiply back, and subtract. 100 ÷ 7 = 14.28..., 14 × 7 = 98, and 100 - 98 = 2. For -17 mod 5: -17 ÷ 5 = -3.4, which rounds down to -4, and -17 - (-20) = 3.

What is a number mod 0?

Undefined, because nothing can be divided by 0. Python raises an error, JavaScript returns NaN and Excel shows #DIV/0!.

More from the Long Division Calculator

Related calculators

Embed this calculator
<div id="compoundpage-long-division-calculator"></div>
<script src="https://compoundpage.com/embed/long-division-calculator.js" async></script>

The same calculation as JSON