IF function in Excel
IF checks a condition and returns one value when it is true and another when it is false.
IF is how a spreadsheet makes a decision. It asks a yes-or-no question about your data and gives one answer for yes and another for no. Pass or fail, due or paid, reorder or in stock: almost every workbook that does more than add uses IF somewhere.
Syntax
=IF(logical_test, value_if_true, [value_if_false])| Argument | What it is |
|---|---|
logical_test | A condition that is either true or false, such as C2>=33. |
value_if_true | What to return when the condition is true. |
value_if_false | What to return when it is false. If you leave it out, the result is FALSE. |
Examples
Each result below is what Excel itself showed for the formula on the sample sheet.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Name | Class | Maths | Science | English |
| 2 | Asha | 8A | 78 | 85 | 91 |
| 3 | Ravi | 8B | 45 | 52 | 60 |
| 4 | Meena | 8A | 92 | 88 | 79 |
| 5 | Kabir | 8B | 33 | 41 | 38 |
| 6 | Tara | 8A | 67 | 72 | |
| 7 | Joy | 8B | 88 | 90 | 84 |
| 8 | Neha | 8A | 54 | 61 | 58 |
| 9 | Imran | 8B | 78 | 73 | 69 |
=IF(C2>=33,"Pass","Fail")Result: PassAsha has 78 in Maths, which is at least 33, so the result is Pass.
=IF(C5>=33,"Pass","Fail")Result: PassKabir has exactly 33. The test is "greater than or equal to", so he passes.
=IF(D6="","Absent",D6)Result: AbsentTara's Science mark is empty. The test for an empty cell is two quotation marks with nothing between them.
=IF(C2>=75,"Distinction",IF(C2>=33,"Pass","Fail"))Result: DistinctionAn IF inside an IF handles three outcomes. 78 is at least 75: Distinction.
=IF(C3>E3,"Better at Maths","Better at English or equal")Result: Better at English or equalThe two sides of a comparison can both be cells. Ravi has 45 in Maths and 60 in English.
=IF(C2>=33,C2*1.1,0)Result: 85.8The results can be calculations: a 10 percent bonus on the marks if passed, otherwise 0.
How it works
IF has three parts, in the order you would say them: if this is true, then show this, otherwise show that.
The condition is a comparison, built with one of these signs.
| Sign | Meaning |
|---|---|
= | equal to |
<> | not equal to |
> | greater than |
< | less than |
>= | greater than or equal to |
<= | less than or equal to |
Text needs quotation marks
Text inside a formula goes in double quotation marks: "Pass". Numbers and cell references do not. =IF(C2>=33,Pass,Fail) gives the error #NAME?, because Excel takes Pass and Fail for names it has never heard of.
Comparing text ignores capital letters: "yes" equals "YES".
Showing nothing
To leave the cell looking empty when the condition fails, return two quotation marks: =IF(B2>0,B2*C2,""). Keep in mind that the cell then holds empty text, not a number, so a formula that later multiplies it may show #VALUE!. When the result feeds other sums, returning 0 is safer.
An IF inside an IF
For more than two outcomes, put a second IF in the place of the "otherwise". The fourth example gives three grades. Excel checks the conditions from left to right and stops at the first true one, so the order matters: test the highest boundary first.
Nesting two or three deep is fine. Beyond that the formula becomes hard to read and easy to break. Better choices for many bands:
- IFS, which lists condition and result pairs without the brackets piling up;
- a small table of boundaries with VLOOKUP or XLOOKUP in approximate mode, which is easier to change later.
Testing two things at once
IF takes one condition. To require two things together, or either of two, wrap them in AND or OR: =IF(AND(C2>=33,D2>=33),"Pass","Fail"). See AND, OR and NOT.
Common mistakes
- Writing a range of numbers the way maths does.
=IF(33<=C2<=100,...)does not work. UseAND(C2>=33,C2<=100). - Numbers in quotation marks.
=IF(C2>=33,"1","0")returns text, which SUM ignores. Write1and0without the marks. - Comparing with text that has stray spaces.
"Paid "with a space at the end does not equal"Paid". - Forgetting the third part. The cell then shows FALSE, which looks odd in a report.
In Google Sheets
IF works identically in Google Sheets.
Related functions
Every result on this page was calculated in Microsoft Excel (version 16.0, build 20326) on 12 November 2026, not typed by hand.
This is an independent help site. It is not connected with or approved by Microsoft. Excel and Microsoft 365 are trademarks of Microsoft Corporation, named here only to say which program a formula is for. The people and figures in the sample sheets are made up.