WTechni logoWTechni

Excel IF Statements: From Basic to Nested (With Examples)

Excel IF statements explained from basic to nested, with copy-paste examples, AND/OR logic, IFS, IFERROR and common error fixes.

Quick answer: An Excel IF statement checks whether a condition is true and returns one value if it is, another if it is not. The syntax is =IF(logical_test, value_if_true, value_if_false) — for example, =IF(B2>=50,"Pass","Fail"). This guide walks from that basic formula up to nested IFs, AND/OR combinations, and the cleaner IFS function, with copy-paste examples.

What Is an Excel IF Statement?

IF is Excel's decision function. It evaluates a logical test — anything answerable with TRUE or FALSE — and returns the first value when the test passes, the second when it fails. The three parts sit inside the parentheses, separated by commas:

=IF(logical_test, value_if_true, value_if_false)

A classic pass/fail example: student scores sit in column B starting at B2, and you want a verdict in column C:

=IF(B2>=50,"Pass","Fail")

Type the formula in C2, press Enter, then drag the fill handle down to grade the whole class in one motion. Text results always need double quotes around them. Numbers must not have them — =IF(B2>=50,1,0) returns true numbers, while quoted "1" and "0" return text that later math ignores. We revisit that trap in the errors section below.

Comparison Operators You Can Use in a Logical Test

The logical test compares two values using one of six operators. Pick the one that matches your question:

OperatorMeaningExample
=Equal to=IF(A2=100,"Perfect","Keep trying")
<>Not equal to=IF(A2<>0,"Active","Closed")
>Greater than=IF(B2>40,"Overtime","Standard")
<Less than=IF(C2<10,"Reorder","Stocked")
>=Greater than or equal to=IF(B2>=50,"Pass","Fail")
<=Less than or equal to=IF(D2<=5,"Low","OK")

Combine a comparison with cell references and IF turns any column into an instant evaluator. Dates work too: =IF(A2<TODAY(),"Overdue","On track") flags late deadlines automatically, recalculating every time the file opens.

Nested IF Statements: Two and Three Levels Deep

A nested IF places a second IF inside the first one's false slot, creating a decision ladder: Excel checks the outer test first, and only if it fails does it evaluate the inner one. Read nested formulas from the outside in, and write the logic in words before typing: "if the score is 90 or more, give an A; otherwise, if it is 80 or more, give a B; otherwise give a C."

Two levels deep — a grade with a middle band:

=IF(B2>=50,IF(B2>=75,"Distinction","Pass"),"Fail")

Three levels deep — full letter grades:

=IF(B2>=90,"A",IF(B2>=80,"B",IF(B2>=70,"C","F")))

Sketch the logic on paper as you write: each opening IF earns one indent, and each level closes with one more parenthesis at the end. Excel colors the bracket pairs in the formula bar when you click inside the formula, which is the fastest way to confirm the closing order matches the opening one.

IF With AND and OR

When a decision depends on multiple conditions, AND and OR collapse what would otherwise be deep nesting. AND returns TRUE only when every condition is true; OR returns TRUE when at least one is.

Bonus eligibility — sales above $10,000 and a customer rating of 4 or higher:

=IF(AND(B2>10000,C2>=4),"Bonus","No bonus")

Priority flag — an account is either overdue or above its credit limit:

=IF(OR(D2>0,E2>F2),"Priority","Normal")

The pattern scales to three or more conditions: =IF(AND(B2>10000,C2>=4,D2="Yes"),"Top tier","Review"). Rule of thumb: use AND when all conditions must hold, and OR when any single one should trigger the result.

IFS: The Cleaner Alternative to Nested IFs

Excel 2019, Excel for Microsoft 365, and Excel for the web include IFS, which lists test-and-result pairs in order and returns the first matching result — no pyramid of closing parentheses:

=IFS(B2>=90,"A",B2>=80,"B",B2>=70,"C",TRUE,"F")

The final TRUE pair acts as the "everything else" catch-all, replacing the last nested slot. IFS is shorter, easier to read, and less error-prone once a ladder grows to four or more outcomes; Microsoft's official support site documents the full syntax and version availability. Use classic nested IF only when the workbook must open in Excel 2016 or older. If you are weighing whether a subscription unlocks features like IFS for your household, our Microsoft 365 Family vs Personal comparison breaks down what each plan includes.

Wrap IF in IFERROR to Keep Sheets Clean

IF itself only errors when it is fed something malformed, but the formulas inside it often divide by zero or hit blank cells. IFERROR catches any error a formula produces and substitutes a value you choose. Instead of showing #DIV/0! when H2 is empty:

=IFERROR(G2/H2,0)

The two nest cleanly as well: =IFERROR(IF(B2>100,"High","Low"),"Check input") returns "Check input" whenever the test itself chokes on bad data. Two cautions: IFERROR hides every error, including typos you needed to see, so wrap only finished formulas. And when the goal is simply to skip blank rows, prefer the explicit guard =IF(H2="","",G2/H2), which masks nothing else.

The IF Family: COUNTIF, SUMIF, and Friends

Counting and summing with a condition use the same logic without writing IF at all. These cousins return numbers rather than labels, and they power most dashboard-style summaries:

Notice the syntax quirk: conditions go inside quotes here (">=50"), unlike the bare comparisons inside IF. All four functions also exist in Google Sheets with identical behavior, which we cover alongside the platform's other differences in our Google Sheets formulas guide.

Common IF Errors and How to Fix Them

Most IF troubles trace back to three causes:

Also remember the separator trap: some regional settings use semicolons instead of commas. If Excel rejects a formula copied from a US website, try =IF(B2>=50;"Pass";"Fail") and it will usually behave.

Day-to-Day Habits That Keep IF Formulas Manageable

Three habits separate clean IF worksheets from tangled ones. First, build one test at a time: enter the simplest =IF(B2>=50,"Pass","Fail"), confirm it fills correctly down the column, and only then complicate it — debugging a ladder you wrote in one go is miserable. Second, lock thresholds with dollar signs before copying: =IF(B2>=$E$1,"High","Low") keeps pointing at the cutoff cell in E1 even when dragged down a thousand rows, so changing the rule later means editing a single cell. Third, keep helper columns visible while you work: a column that shows each intermediate TRUE or FALSE makes review painless, and you can hide it right before sharing the file.

IF Function Cheat Sheet (Copy and Paste)

Ten patterns that cover nearly every IF question we receive, with what each one returns:

Function or patternSyntaxExampleWhat it returns
IF=IF(test, true_val, false_val)=IF(B2>=50,"Pass","Fail")One of two values based on a test
Nested IF=IF(t1, v1, IF(t2, v2, v3))=IF(B2>=90,"A",IF(B2>=80,"B","F"))First matching result down a ladder
IF with AND=IF(AND(c1, c2), v1, v2)=IF(AND(B2>10000,C2>=4),"Bonus","No")Value when ALL conditions are true
IF with OR=IF(OR(c1, c2), v1, v2)=IF(OR(D2>0,E2>F2),"Priority","Normal")Value when ANY condition is true
IFS=IFS(t1, v1, t2, v2, TRUE, default)=IFS(B2>=90,"A",B2>=80,"B",TRUE,"F")Result of the first TRUE test
IFERROR=IFERROR(formula, fallback)=IFERROR(G2/H2,0)Formula result, or fallback on any error
COUNTIF=COUNTIF(range, criteria)=COUNTIF(B2:B31,">=50")Count of cells meeting a condition
SUMIF=SUMIF(range, criteria, sum_range)=SUMIF(A2:A31,"West",C2:C31)Sum of rows meeting a condition
AVERAGEIF=AVERAGEIF(range, criteria, avg_range)=AVERAGEIF(A2:A31,"West",C2:C31)Average of rows meeting a condition
COUNTIFS=COUNTIFS(r1, c1, r2, c2)=COUNTIFS(B2:B31,">=50",C2:C31,"<70")Count meeting multiple conditions

A practical pairing: put letter grades in a validated cell so results stay consistent when others edit the sheet — our Excel drop-down list guide shows the setup in under two minutes.

The Bottom Line

Master =IF(logical_test, value_if_true, value_if_false) and you can automate decisions in any spreadsheet: grades, budgets, inventory flags, overdue invoices. Start with one condition, graduate to AND and OR for multi-part logic, and reach for IFS before you nest three levels deep. When a sheet needs counts or totals rather than labels, switch to COUNTIF and SUMIF instead of forcing IF to do the counting.

Open a blank sheet and rebuild the pass/fail example from this guide — ten minutes of hands-on typing beats an hour of reading, and every pattern above works identically in Excel for Windows, Mac, and the web. If you are building a leaner toolkit around Excel, our roundup of the best productivity apps covers the rest of the stack.

#excel#formulas
Wasim Akram

Wasim Akram

Wasim Akram is an independent web publisher and digital entrepreneur with 8+ years of experience in SEO, web publishing, and technical research. Since 2018, he has been building niche websites, online tools, custom CMS platforms, and WordPress products — including the FlynCache Purge caching plugin published in the official WordPress Plugin Directory. Instead of following a traditional development path, he has learned by building real-world projects, testing everything hands-on, and using AI-powered workflows to turn ideas into practical products. At WTechni, every guide is backed by thorough research, practical testing, and one simple rule: give readers accurate, useful information they can act on.

Ready to Learn More?

Explore our complete guides and resources to get the answers you need.

Browse All Articles