Start free
Logical

IF function

IF checks a condition and returns one value when it's true and another when it's false: =IF(B2>=50, "Pass", "Fail").

Available in every version of Excel, Excel for the web and Google Sheets
On this page

IF syntax

=IF(logical_test, value_if_true, [value_if_false])
ArgumentRequiredWhat it means
logical_testYesSomething that is TRUE or FALSE, such as B2>=50 or A2="Paid".
value_if_trueYesWhat to return when the test is TRUE.
value_if_falseNoWhat to return when it's FALSE. Leave it out and you get FALSE.

Examples

Pass or fail

A score of 50 or more passes. Text results go in double quotes.

C2=IF(B2>=50,"Pass","Fail")
RowABC
1StudentScoreResult
2Ana72Pass
3Ben48
=IF(B2>=50,"Pass","Fail") → Pass

Two conditions with AND

A bonus only when sales are over 10,000 and the region's target was hit. AND is TRUE only when every test inside it is.

D2=IF(AND(B2>10000,C2="Yes"),B2*5%,0)
RowABCD
1RepSalesTarget hitBonus
2Lena12,400Yes620
3Marc9,800Yes
=IF(AND(B2>10000,C2="Yes"),B2*5%,0) → 620

Three outcomes with a nested IF

The second IF only runs when the first test is FALSE. For more than three outcomes, IFS or a lookup table is easier to read.

C2=IF(B2>=100,"Free",IF(B2>=30,"Standard","Paid"))
RowABC
1OrderAmountShipping
2#1001$35.00Standard
=IF(B2>=100,"Free",IF(B2>=30,"Standard","Paid")) → Standard

Practise it

New data, so you can't copy the answer above. We check the number your formula returns, then change the data to make sure it still holds.

Your task: In C2, show "Reorder" when stock in B2 is below 20, otherwise "OK".

Graded live
RowABC
1ItemStockStatus
2Paper12

Write the formula in the bar above, then press Check or Enter.

Hint

Test B2<20. The value if true is "Reorder", the value if false is "OK", both in double quotes.

Solution

=IF(B2<20,"Reorder","OK") Any formula that returns the same result passes.

Common mistakes

  1. Text without quotes. IF(B2>=50,Pass,Fail) returns #NAME?, because Excel reads Pass as a name. Write "Pass".
  2. Numbers in quotes. IF(B2>=50,"1","0") returns text, and SUM ignores text. Write 1 and 0 without quotes.
  3. Writing 10 < B2 < 20. Excel can't chain comparisons. Use AND(B2>10,B2<20).
  4. Deeply nested IFs. Past three or four levels they're hard to check. Use IFS, or put the bands in a table and look them up with XLOOKUP.

FAQ

How many IFs can I nest?

Excel allows 64, but past three or four the formula is hard to read and easy to get wrong. Use IFS or a lookup table instead.

How do I test for a blank cell?

Use =IF(A2="","Empty","Filled") or =IF(ISBLANK(A2),...). The first also treats a formula that returns "" as blank.

Can IF check if a cell contains some text?

Combine it with SEARCH: =IF(ISNUMBER(SEARCH("refund",A2)),"Yes","No") finds "refund" anywhere in A2, ignoring case.

Guides that use IF

Worked problems with practice sheets.

Errors & fixesPractice sheet

#DIV/0! error in Excel: what it means and how to fix it

#DIV/0! means a formula divided by zero or by an empty cell. Why it happens, averages of nothing included, and how to show a clean result, with a practice sheet.

2 min read · Updated
Errors & fixesPractice sheet

#NAME? error in Excel: what it means and how to fix it

#NAME? means Excel doesn't recognise a word in your formula: a misspelt function, text without quotes, a missing colon. Find it and fix it, with a practice sheet.

2 min read · Updated

Know IF? Prove it on a real sheet.

Practise IF and the functions around it in a live grid that grades your result and explains your mistakes.

Runs in your browser · Graded on your result · No install