Lesson 60 of 92 · Free Excel Course
Excel · Excel function reference
Excel MOD Function: Syntax, Examples and Common Errors
How the Excel MOD function returns a remainder: syntax, negative numbers, even/odd tests, banded rows, overnight hours and #DIV/0! fixes. Free practice file.
The MOD function gives you the remainder after one number is divided by another. =MOD(10,3) returns 1, because 3 goes into 10 three times with 1 left over. The answer is always a number, and Excel gives it the same sign as the number you divide by. That sounds like a small detail, but it is what makes MOD so handy for even/odd tests, every-other-row shading, splitting minutes into hours, and working out hours for shifts that cross midnight. MOD is available in Excel for Microsoft 365 (Windows, Mac and the web), Excel 2024, Excel 2021, Excel 2019 and Excel 2016.
Syntax
=MOD(number, divisor)
- number (required): the number you want to divide. It can be typed in, a cell reference such as A2, or another formula.
- divisor (required): the number you divide by. It can't be 0; if it is, MOD returns #DIV/0!. A decimal divisor is fine, and a divisor of 1 is a common trick for pulling out the decimal part.
Neither argument has a default, so both must be there. Behind the scenes, Microsoft defines the result as number - divisor*INT(number/divisor). INT always rounds down, and that one fact explains every result with negative numbers below.
Examples
Microsoft's example: what happens with negative numbers
This is the example from Microsoft's MOD page, with the numbers in columns A and B so you can see each one.
| A | B | C | |
|---|---|---|---|
| 1 | Number | Divisor | MOD |
| 2 | 3 | 2 | 1 |
| 3 | -3 | 2 | 1 |
| 4 | 3 | -2 | -1 |
| 5 | -3 | -2 | -1 |
Row 3 is the one that surprises people. Most of us expect "-3 divided by 2 leaves -1", but Excel says 1. Run it through Microsoft's formula: -3 divided by 2 is -1.5, INT rounds that down to -2, and -3 minus 2 times -2 is -3 + 4 = 1. Think of it as "how far above the last multiple of 2 below -3" (that multiple is -4). When the divisor is negative, as in rows 4 and 5, the result is negative too.
Split minutes into hours and minutes
A time-tracking app exports durations in minutes. INT gives the full hours and MOD gives the minutes left over.
| A | B | |
|---|---|---|
| 1 | Minutes | Duration |
| 2 | 135 | 2 h 15 min |
| 3 | 200 | 3 h 20 min |
| 4 | 45 | 0 h 45 min |
The same pattern works for any "full units plus leftover" job: eggs into boxes of 12, inches into feet (divisor 12), or days into weeks (divisor 7).
Even or odd, and every nth row
A number is even when dividing by 2 leaves nothing. Change the 2 to 3 and you test for "every 3rd".
| A | B | |
|---|---|---|
| 1 | Order # | Even or odd |
| 2 | 1041 | Odd |
| 3 | 1042 | Even |
| 4 | 1043 | Odd |
| 5 | 1044 | Even |
Put the same idea inside ROW to shade every other row, which Microsoft recommends for banded rows:
- Select the cells to shade.
- On the Home tab, click Conditional Formatting > New Rule.
- Choose Use a formula to determine which cells to format.
- Type
=MOD(ROW(),2)=0, click Format, pick a color on the Fill tab, and click OK twice.
Use =MOD(ROW(),3)=0 for every 3rd row, or =MOD(COLUMN(),2)=0 for columns. To add up every other row, use =SUMPRODUCT((MOD(ROW(B2:B13),2)=0)*B2:B13). The conditional formatting lesson covers rules in full.
Hours for a shift that crosses midnight
Excel stores a time as a fraction of a day, so 9:30 PM is about 0.896 and 5:45 AM is about 0.240. End minus start is negative here, and Excel shows a negative time as ####. A divisor of 1 adds a whole day to any negative result and leaves normal shifts alone.
| A | B | C | |
|---|---|---|---|
| 1 | Start | End | Hours |
| 2 | 9:30 PM | 5:45 AM | 8.25 |
| 3 | 8:00 AM | 4:30 PM | 8.5 |
The work schedule project uses this in a full timesheet with breaks.
Common errors
- #DIV/0! The divisor is 0 or an empty cell (an empty cell counts as 0). Fix the data, or hide the error until a divisor is entered:
=IF(B2=0,"",MOD(A2,B2)). - #VALUE! One argument is text that isn't a number, such as "12 pcs" from an export. Remove the text or convert the column (the text functions lesson shows how).
- Wrong sign with negative numbers. Not a bug: the result follows the divisor, so
=MOD(-17,5)is 3. If you need the remainder to keep the first number's sign (-2 here, as in many programming languages), use=A2-B2*TRUNC(A2/B2). - Decimal part of a negative number looks wrong.
=MOD(-12.75,1)gives 0.25, not 0.75, for the same reason. Use=MOD(ABS(A2),1)to get 0.75 for both signs. See the ABS function. - A remainder that is a hair off. Excel stores decimals in binary, so the decimal part of 5.1 can come out as 0.0999999999999996 rather than exactly 0.1, and a test such as
=MOD(A2,1)=0.1can return FALSE. Round before you compare:=ROUND(MOD(A2,1),2)=0.1. - #### in a time column. You used plain end minus start for an overnight shift. Wrap it in
MOD(...,1)as above.
Related functions
- Subtract, multiply and divide: the lesson on division, QUOTIENT and #DIV/0!.
- ABS function: removes the sign, useful before MOD with negatives.
- PRODUCT function and POWER function: the other arithmetic functions.
- Dates and times: why times are fractions of a day.
Try it yourself
Download the practice workbook. The Practice sheet has yellow cells for a negative remainder, a decimal part, minutes to hours, an even/odd test, an overnight shift and an every-other-row total. The Answers sheet has the finished formulas, so you can check each result.
Frequently asked questions
Why does =MOD(-3,2) return 1 and not -1?
In Excel the result of MOD always takes the sign of the divisor. Excel works it out as number minus divisor times INT(number/divisor), and INT rounds down: INT(-1.5) is -2, so -3 - 2*(-2) = 1. If you want the remainder to keep the sign of the first number instead, use =A2-B2*TRUNC(A2/B2).
How do I check if a number is even or odd in Excel?
Divide by 2 and look at the remainder: =IF(MOD(A2,2)=0,"Even","Odd"). Excel also has ISEVEN and ISODD, which give TRUE or FALSE directly, but the MOD version lets you test for any step, such as every 3rd or 5th number.
How do I get only the decimal part of a number?
Use a divisor of 1: =MOD(A2,1) turns 12.75 into 0.75. For negative numbers it counts up from the next whole number below, so -12.75 gives 0.25. Use =MOD(ABS(A2),1) if you want 0.75 for both.
What is the difference between MOD and QUOTIENT?
They are two halves of the same division. QUOTIENT gives the whole number of times the divisor fits, MOD gives what is left over. For 135 minutes, =QUOTIENT(135,60) is 2 and =MOD(135,60) is 15: 2 hours 15 minutes.