Home  /  Blog  /  Logical & Conditional
Logical & Conditional

IF Formula in Excel — With Examples (Nested IF, AND, OR, IFS)

By admin 1 December 2026 Logical & Conditional

You have a list of exam scores and you need a column that decides: 90 and above is an A, 80 and above is a B, and below 60 is an F. Or a list of sales and you need a Yes or No: over $1,000, Yes, otherwise No. That is what IF does — it tests one condition and returns one value when the test is true and another when it is false. The formula has three parts, =IF(logical_test, value_if_true, value_if_false), and everything else in this guide is that pattern repeated: two conditions with AND and OR, several levels with a nested IF or IFS, and the two surprises — FALSE and 0 — that catch everyone once. Every example runs on a table in this article, so you can check each answer yourself.

Quick takeaway: one test, two answers.

  • =IF(logical_test, value_if_true, value_if_false) — true gives the first value, false gives the second.
  • AND means all conditions must be true. OR means one is enough. NOT reverses a test.
  • Several levels: nest IFs, or use IFS (Excel 2019 and later).
  • Text in quotes: "Pass". Numbers without quotes: 1000.
  • Leave the third part out and a false test returns FALSE, not 0.
IF Formula in Excel — With Examples (Nested IF, AND, OR, IFS)

The Formula — Three Parts

=IF(logical_test, value_if_true, value_if_false)
PartWhat it does
logical_testThe condition Excel checks — a comparison like A2>=90, or a function like AND(...)
value_if_trueThe value returned when the test is TRUE — text, a number, or another formula
value_if_falseThe value returned when the test is FALSE — text, a number, or another formula

The third part is technically optional, but leaving it out is how the FALSE surprise happens — the section near the end covers it. Text goes in double quotes, numbers do not: =IF(A2>=90, "A", "F") works, and =IF(C2>1000, C2-1000, 0) works.

The Worked Tables — Grades, Pass/Fail, and Yes/No

Three small tables, one per idea. Every result below was checked against them.

Table 1 — exam scores, for the grades sections:

StudentScore
Aisha92
Ben78
Carla65
Dan88
Eva54
Finn71
Grace83
Hugo47
Ivy96
Jack59

Table 2 — two subjects, for the AND/OR sections:

StudentMathEnglish
John5565
Mike4870
Sara7258
Omar4559
Lina8085

Table 3 — the sales table from the COUNTIF and SUMIF articles, for the Yes/No section: the same ten orders (Alex, Priya, Jordan, Sam, Taylor — $1,200, $850, $2,400, $450, $1,750, $600, $900, $1,100, $300, $1,500). Total sales $11,050.

One Condition — Pass or Fail, Yes or No

The simplest IF. One test, two answers.

GoalFormulaResult
Score 60 or above passes=IF(A2>=60, "Pass", "Fail")Aisha Pass, Eva Fail, Hugo Fail, Jack Fail
Sale over $1,000 gets a Yes=IF(C2>1000, "Yes", "No")5 Yes, 5 No
Two cells equal?=IF(A2=B2, "Yes", "No")“Yes” when they match, “No” when they do not

The sales question gives 5 Yes and 5 No: $1,200, $2,400, $1,750, $1,100 and $1,500 are over $1,000. And the third row is the answer to “if x = y”: put the comparison itself in the test — =IF(A2=B2, "Yes", "No") — and Excel returns Yes when the two cells hold the same value.

Several Levels — Grades with a Nested IF

One IF gives two answers. For five grades, put an IF inside the false part of the one before it. Excel checks each condition in turn until one is true.

=IF(A2>=90, "A", IF(A2>=80, "B", IF(A2>=70, "C", IF(A2>=60, "D", "F"))))
ScoreGradeWhy
92A92 is 90 or above
78C78 is below 80, but 70 or above
65D65 is below 70, but 60 or above
88B88 is 80 or above
54F54 is below 60
71C71 is 70 or above
83B83 is 80 or above
47F47 is below 60
96A96 is 90 or above
59F59 is below 60 — one point short of a D

Grade counts: A = 2, B = 2, C = 2, D = 1, F = 3 — ten students, all accounted for. Notice the order matters: the test must go from the highest boundary down. If you tested >=60 first, every score of 60 or above would return “D” and the higher grades would never be reached. And notice the trap in the last row: 59 is one point short of a D, and the formula does not care — a boundary is a boundary.

The Same Grades with IFS — Easier to Read

IFS does the same job without nesting. Each condition gets its own result, in pairs, and the last pair is the catch-all — TRUE with the final result, so that anything left over still gets an answer.

=IFS(A2>=90, "A", A2>=80, "B", A2>=70, "C", A2>=60, "D", TRUE, "F")
Nested IFIFS
Same result?Yes — identical grades for all ten scoresYes — identical grades for all ten scores
NeedsAny Excel versionExcel 2019 and later
Reading itFour closing brackets at the endFlat pairs, no nesting
If no condition matchesThe last value (“F”) is returned#N/A — unless the last pair is TRUE

The rule of thumb: three levels is fine as a nested IF; five levels means use IFS. And never leave the final TRUE out of an IFS — without it, a score that matches nothing returns #N/A instead of a grade.

Two Conditions — IF with AND and OR

When one condition is not enough, put AND or OR in the test slot. AND returns TRUE only when every condition inside it is TRUE. OR returns TRUE when at least one condition is TRUE. Each accepts up to 255 conditions.

Pass needs Math over 50 and English over 60:

=IF(AND(B2>50, C2>60), "Pass", "Fail")

Pass needs Math over 50 or English over 60:

=IF(OR(B2>50, C2>60), "Pass", "Fail")
StudentMathEnglishAND (both)OR (either)
John5565PassPass
Mike4870FailPass
Sara7258FailPass
Omar4559FailFail
Lina8085PassPass

AND passes 2 students (John and Lina). OR passes 4 (everyone except Omar). Mike is the row that shows the difference: his English is 70, so OR passes him, but his Math is 48, so AND fails him. Sara is the mirror image: her Math is 72, so OR passes her, but her English is 58, so AND fails her.

IF with NOT, and Combining AND with OR

NOT reverses a test: =IF(NOT(A2>50), "Below 50", "50 or above") returns “Below 50” when the score is 50 or less. And the two can combine for a real-world rule — for example, a discount for East orders over $1,000, or for any order over $2,000:

=IF(OR(AND(B2="East", C2>1000), C2>2000), "Discount", "No discount")

On the sales table that gives a discount to 2 orders: the East orders are rows 2 ($1,200), 4 ($2,400), 7 ($600) and 8 ($900), and of those only rows 2 and 4 are over $1,000. The fallback rule — any order over $2,000 — catches row 4 only, which is already counted. So the discount rows are 2 and 4. The AND inside the OR does the precise work, and the OR adds the fallback rule.

IF Returning a Number — The Amount Over $1,000

IF does not have to return text. It can return a number, or another formula’s result.

=IF(C2>1000, C2-1000, 0)
SaleAmount over $1,000
$1,200$200
$850$0
$2,400$1,400
$450$0
$1,750$750
$600$0
$900$0
$1,100$100
$300$0
$1,500$500

Total over $1,000: $2,950. The 0 in the third part is doing real work here: without it, the rows at or below $1,000 would return FALSE, and adding the column would break. This is the answer to “if 0”: when you want a number back, always give IF a number for the false case — usually 0.

Why IF Returns FALSE — and Why It Returns 0

The two surprises, and they are both the same mistake: a missing third part.

SymptomWhat happenedFix
IF returns FALSEThe third part was left out: =IF(A2>=60, "Pass") has no value for a fail, so Excel returns FALSEGive the third part: =IF(A2>=60, "Pass", "Fail")
IF returns 0The false part returns a number, or the test compares a blank cell — a blank cell is 0 to ExcelGive the false part explicitly: =IF(A2="", "", A2*2) returns a blank for a blank cell instead of 0
IF returns #N/AAn IFS with no matching condition and no final TRUE pairEnd every IFS with TRUE, "your default"
IF returns #VALUE!The test compares text with a number, e.g. A2>50 when A2 holds “abc”Check the cell holds a number first

The blank-cell rule deserves its own line, because it connects to another article: a blank cell is 0 to Excel, so =IF(A2="", "", A2*2) is the pattern that returns a blank instead of 0 — the full guide is the return blank instead of zero article.

Common Mistakes

MistakeWhat happensFix
You tested the lowest boundary firstEvery score of 60 or above returns “D” and the higher grades are never reachedTest from the highest boundary down: 90, then 80, then 70, then 60
You forgot a closing bracketExcel shows an error or adds a bracket in the wrong placeCount the IFs: four IFs need four closing brackets at the end
You quoted a number=IF(A2>="90", "A", "F") compares text with a number and misbehavesNumbers without quotes: A2>=90
You used AND when you meant OROnly 2 students pass instead of 4AND means all must be true; OR means one is enough
You nested five levels deepThe formula works but nobody can read it, including you next monthUse IFS — flat pairs, one condition per line of logic
You left the third part outA false test returns FALSEAlways give value_if_false, even if it is just "" or 0

Frequently Asked Questions

What is the IF formula in Excel? =IF(logical_test, value_if_true, value_if_false). For example, =IF(A2>=60, "Pass", "Fail") returns Pass when the score is 60 or above, and Fail otherwise.

How do I write an IF formula with two conditions in Excel? Put AND or OR in the test: =IF(AND(B2>50, C2>60), "Pass", "Fail") needs both, =IF(OR(B2>50, C2>60), "Pass", "Fail") needs either one.

How do I write multiple IF statements in Excel? Nest them: =IF(A2>=90, "A", IF(A2>=80, "B", IF(A2>=70, "C", IF(A2>=60, "D", "F")))). Or use IFS in Excel 2019 and later: =IFS(A2>=90, "A", A2>=80, "B", A2>=70, "C", A2>=60, "D", TRUE, "F").

What is the difference between IF and IFS? IF handles one test with two answers, and nesting gives more levels. IFS handles several tests in flat pairs, is easier to read, and needs a final TRUE pair or it returns #N/A when nothing matches.

How do I make an IF formula return Yes or No in Excel? Put the words in the two result slots: =IF(C2>1000, "Yes", "No"). On the sales table that gives 5 Yes and 5 No.

Why does my IF formula return FALSE? The third part was left out. =IF(A2>=60, "Pass") has no value for a fail, so Excel returns FALSE. Add it: =IF(A2>=60, "Pass", "Fail").

How many IFs can I nest in Excel? Excel allows nesting up to 64 levels. In practice, stop at three or four and switch to IFS — a 64-level nested IF is unreadable.

That is the IF formula in Excel: one test, two answers — =IF(logical_test, value_if_true, value_if_false) — with AND when all conditions must be true, OR when one is enough, and a nested IF or IFS when there are several levels. On the tables in this guide, that one pattern answers every question: ten scores become two As, two Bs, two Cs, one D and three Fs; two subjects become two passes under AND and four under OR; ten sales become five Yes and five No; and the amount over $1,000 adds up to $2,950. Remember the two things that catch everyone once: test from the highest boundary down, or the lower grades swallow the higher ones, and always give the third part — a false test with nowhere to go returns FALSE, not 0. From here, the next functions worth learning are the ones this one sits next to — the COUNTIF formula for counting instead of deciding, the SUMIF formula for adding instead of deciding, and the full learning order for the whole site is on the Excel Formulas hub and the Logical & Conditional category page.


About admin

Author of Excel formula guides on this blog.

View all guides by admin →

Keep Learning

Related guides