
Tutorials
Excel IF Function Explained: Examples for Beginners
Learn the Excel IF function with clear examples: basic IF, AND and OR, nested IF, IFS and IFERROR, plus the mistakes that trip people up.
By ExcelPanda Team · Published · 5 min read
The basic IF formula
Say column B holds exam scores and you want to mark each one Pass or Fail, with 50 as the pass mark:
=IF(B2>=50, "Pass", "Fail")Excel checks whether B2 is at least 50. If it is, the cell shows Pass. If not, it shows Fail. Copy the formula down the column and every row is marked.
Comparison operators
Comparison operators
| Operator | Meaning | Example |
|---|---|---|
| = | Equal to | A2="Paid" |
| <> | Not equal to | A2<>"Paid" |
| > | Greater than | B2>100 |
| >= | Greater than or equal to | B2>=50 |
| < | Less than | B2<10 |
| <= | Less than or equal to | B2<=10 |
Combine conditions with AND and OR
Use AND when every condition must be true, and OR when any one is enough.
=IF(AND(B2>=50, C2>=50), "Pass", "Fail")=IF(OR(D2="Gold", D2="Silver"), "Discount", "No discount")Nested IF and the easier IFS
To grade scores as A, B or C you can put an IF inside another IF:
=IF(B2>=80, "A", IF(B2>=60, "B", "C"))Excel tests the conditions in order and stops at the first true one. With more levels, IFS reads more cleanly:
=IFS(B2>=80, "A", B2>=60, "B", TRUE, "C")The final TRUE acts as a catch-all for everything that did not match earlier.
Handle errors with IFERROR
If a formula might return an error, wrap it in IFERROR to show something friendlier:
=IFERROR(B2/C2, 0)Common mistakes
- Forgetting quotation marks around text. Write "Pass", not Pass.
- Wrong order in nested IFs. Test the strictest condition first, or an early test will catch everything.
- Numbers stored as text. They look like numbers but do not compare as numbers.
Once IF is comfortable, move on to counting and summing with conditions, as laid out in our 30-day Excel plan.
Frequently asked questions
What does the IF function do in Excel?
IF tests a condition and returns one value if it is true and another if it is false.
How many IFs can I nest?
Modern versions of Excel allow many levels of nesting, but long chains are hard to read. IFS or a lookup table is usually clearer.
Which versions have IFS?
IFS is available in Excel 2019 and later and in Microsoft 365. It is not in Excel 2016 or earlier.
Why does my IF return the wrong result?
Common causes are numbers stored as text, extra spaces in text, or a condition that is the wrong way round. Check the cell values and the order of your tests.
Can IF check text?
Yes. Put the text in quotation marks, for example =IF(A2="Paid","Done","Chase"). Text comparisons ignore upper and lower case.
Sources and disclaimers
ExcelPanda is not affiliated with or endorsed by Microsoft. Microsoft and Excel are trademarks of the Microsoft group of companies.
.png)