Division with a remainder
When a whole number does not divide another exactly, the division leaves a remainder. Euclidean division writes any dividend a and non-zero divisor b as a = b × q + r, where q is the quotient and r the remainder, with 0 ≤ r < |b|. This is the long division taught in school, and it is also the “mod” operation used in programming, calendars and clocks.
Worked example: 47 ÷ 5
- 5 goes into 47 nine times: 5 × 9 = 45.
- Remainder: 47 − 45 = 2.
- So 47 = 5 × 9 + 2: quotient 9, remainder 2.
- As a decimal: 47 ÷ 5 = 9.4; as a mixed number: 9 2/5.
Negative numbers and programming languages
With negative numbers, conventions differ:
- Euclidean division keeps the remainder positive: −7 = 5 × (−2) + 3, so the remainder is 3.
- Truncated division, used by the % operator in C, C++, Java and JavaScript, rounds the quotient toward zero: −7 % 5 = −2.
- Floored division, used by % in Python and by MOD in spreadsheets, gives a remainder with the sign of the divisor: −7 % 5 = 3, and 7 % −5 = −3.
The calculator shows all three, so you can check what your code will return.
Results for other dividends (divisor 5)
| Dividend | Quotient | Remainder | Decimal |
|---|---|---|---|
| −7 | −2 | 3 | −1.4 |
| 0 | 0 | 0 | 0 |
| 7 | 1 | 2 | 1.4 |
| 47 | 9 | 2 | 9.4 |
| 100 | 20 | 0 | 20 |
| 365 | 73 | 0 | 73 |
Everyday uses of the remainder
- Packing: 47 eggs in boxes of 6 fill 7 boxes with 5 eggs left over.
- Calendars: 100 days from a Monday is a Wednesday, because 100 mod 7 = 2.
- Clocks: 30 hours after 9:00 is 15:00 the next day, since (9 + 30) mod 24 = 15.
- Even and odd: a number is even when its remainder by 2 is 0.
- Divisibility tests: a number is divisible by 3 or 9 when the sum of its digits is.
- Check digits: ISBNs, credit card numbers (Luhn algorithm) and IBANs use remainders to catch typing errors.
Remainder and fractions
The remainder over the divisor is the fractional part: 2 ÷ 5 = 0.4. If you only need to know whether b divides a, check that the remainder is 0. Dividing by 0 is undefined, so the calculator refuses a divisor of 0.