MOD function
Returns the remainder after dividing one number by another; the result has the sign of the divisor.
Available in All versions of Excel, Excel for the web, Excel for Mac
In every Excel versionWorks in Google Sheets
Syntax
MOD(number, divisor)| Argument | What it means | |
|---|---|---|
number | Required | The number to divide. |
divisor | Required | The number to divide by. Cannot be 0. |
Returns: The remainder, with the same sign as divisor.
How MOD works
MOD gives what is left over after a division: 145 items in boxes of 12 make 12 full boxes with 1 left, and =MOD(145, 12) returns that 1. Together with QUOTIENT or INT it splits any quantity into complete groups and a remainder: minutes into hours and minutes, days into weeks and days, stock into pallets and loose items.
Because the remainder repeats in a cycle, MOD is also the standard tool for patterns: MOD(ROW(), 2) alternates 0 and 1 for banded rows, MOD(n, 7) maps days to a weekly cycle, and MOD(end-start, 1) calculates a shift that crosses midnight, since times are fractions of a day.
With negative numbers Excel's MOD takes the sign of the divisor: MOD(-7, 3) is 2 and MOD(7, -3) is −2. Many programming languages (and VBA's Mod operator) give −1 and 1 instead, so results can differ when you port formulas. Excel's rule is number − divisor × INT(number / divisor).
Examples
1Loose items after filling boxes
| A | B | C | |
|---|---|---|---|
| 1 | Item | Value | |
| 2 | Items to pack | 145 | 1 |
| 3 | Per box | 12 |
Result: 1
12 × 12 = 144, so 1 item remains. =QUOTIENT(B2, B3) gives the 12 full boxes.
2Flag even invoice numbers
| A | B | |
|---|---|---|
| 1 | Invoice no. | Even? |
| 2 | 10457 | FALSE |
| 3 | 10458 |
Result: FALSE
10457 / 2 leaves 1, so the test is FALSE; filled down, B3 shows TRUE. The same logic in conditional formatting with =MOD(ROW(),2)=0 shades every other row.
3The sign follows the divisor
| A | B | C | |
|---|---|---|---|
| 1 | Number | Divisor | |
| 2 | -7 | 3 | 2 |
| 3 | 7 | -3 |
Result: 2
−7 = 3 × (−3) + 2, so the remainder is 2 (positive, like the divisor). In C3, =MOD(A3, B3) returns −2.
4Shift length across midnight
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Employee | Start | End | |
| 2 | Night guard | 22:00 | 6:30 | 8:30 |
Result: 8:30
6:30 − 22:00 is negative (−15.5 hours); MOD with 1 day wraps it to 8.5 hours. Format the cell as h:mm.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#DIV/0! | The divisor is 0 or an empty cell. | Check the divisor or wrap in IF(B3=0, "", MOD(...)). |
#NUM! | In some versions very large numbers relative to the divisor cannot be handled. | Use =A2-B2*INT(A2/B2) instead. |
Unexpected tiny decimals | Decimal divisors like 0.1 are not stored exactly, so MOD(1, 0.1) may show 0.1 instead of 0. | Work with whole numbers (scale by 10/100) or round the result. |
Tips
- Decimal part of a positive number:
=MOD(A2, 1). - Every n-th row:
=MOD(ROW()-ROW($A$2), 3)=0marks rows 2, 5, 8… - Convert 135 minutes:
=QUOTIENT(135,60)&" h "&MOD(135,60)&" min"gives 2 h 15 min.
Questions
Why does MOD(-7, 3) return 2 and not -1?
Excel's MOD uses the sign of the divisor, based on INT (rounding down). That keeps remainders in the range 0 to divisor−1, which is what you want for cycles like days of the week.
How do I calculate hours worked across midnight?
Use =MOD(end-start, 1) and format as h:mm. MOD turns the negative difference into the correct positive time.
Google Sheets
MOD also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.
MOD in other languages
In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.
| Language | Function name |
|---|---|
| Danish | REST |
| Dutch | REST |
| Finnish | JAKOJ |
| German | REST |
| Hungarian | MARADÉK |
| Italian | RESTO |
| Norwegian (Bokmål) | REST |
| Portuguese (Portugal) | RESTO |
| Russian | ОСТАТ |
| Spanish | RESIDUO |
| Swedish | REST |
Recipes that use MOD
- How to calculate overtime in Excel
- How to convert decimal hours to time in Excel
- How to shade alternate rows in Excel
- How to sum time over 24 hours in Excel
- How to use conditional formatting with a formula in Excel