How to Use the IF Function in Excel (with Examples)
The IF function returns one value when a condition is true and another when it is false. The syntax is =IF(logical_test, value_if_true, value_if_false). Here is how to use it, nest it, and avoid the usual mistakes.
The IF function is how you make Excel decide. It checks a condition and returns one answer if it is true and a different answer if it is false — the building block of nearly every smart spreadsheet.
The IF syntax
=IF(logical_test, value_if_true, value_if_false)
| Part | Meaning |
|---|---|
| logical_test | The condition to check, e.g. B2>100 |
| value_if_true | What to return when the condition is met |
| value_if_false | What to return when it is not |
A simple example
To label sales in B2 as "Pass" or "Fail" based on a target of 100:
=IF(B2>=100, "Pass", "Fail")
Text values must go in double quotes. If you want a number instead, leave the quotes off, for example =IF(B2>=100, 1, 0).
Nesting IF and combining with AND / OR
You can put an IF inside another IF for more than two outcomes, or use AND and OR to test several conditions at once, like =IF(AND(B2>=100, C2="VIP"), "Bonus", "Standard"). If you have Microsoft 365, the IFS function is cleaner than deeply nested IFs.
IF pairs naturally with lookups — use it to act on the result of VLOOKUP. And if an IF returns #VALUE!, see how to fix the #VALUE! error.
Frequently asked questions
Can the IF function check text?
Yes. Use quotes around the text, for example =IF(A2="Yes", 1, 0). Text comparisons in Excel are not case-sensitive, so "yes" and "YES" are treated the same.
How many IFs can you nest?
Excel allows up to 64 nested IFs, but anything beyond three or four becomes hard to read. Use IFS, VLOOKUP against a lookup table, or the SWITCH function instead for many outcomes.