Math & trig function

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)
ArgumentWhat it means
numberRequiredThe number to divide.
divisorRequiredThe 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

C2fx=MOD(B2, B3)
ABC
1ItemValue
2Items to pack1451
3Per box12

Result: 1

12 × 12 = 144, so 1 item remains. =QUOTIENT(B2, B3) gives the 12 full boxes.

2Flag even invoice numbers

B2fx=MOD(A2, 2)=0
AB
1Invoice no.Even?
210457FALSE
310458

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

C2fx=MOD(A2, B2)
ABC
1NumberDivisor
2-732
37-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

D2fx=MOD(C2-B2, 1)
ABCD
1EmployeeStartEnd
2Night guard22:006:308: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.

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 17 KB

Common errors and how to fix them

ErrorWhy it happensFix
#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 decimalsDecimal 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)=0 marks 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.

LanguageFunction name
DanishREST
DutchREST
FinnishJAKOJ
GermanREST
HungarianMARADÉK
ItalianRESTO
Norwegian (Bokmål)REST
Portuguese (Portugal)RESTO
RussianОСТАТ
SpanishRESIDUO
SwedishREST

Recipes that use MOD