IF Statement Complete Guide — IF, IFS, IFERROR, SWITCH, and Nested Logic
Home Guides IF Statement Complete Guide
📖 Complete Guide · Pillar Content

IF Statement — the complete guide

The IF function is Excel's most fundamental logical tool — but it's only the beginning. Modern Excel gives you an entire family: IF, IFS, IFERROR, IFNA, SWITCH, AND, OR, NOT. This guide covers every one, when to reach for which, and the 10 patterns that solve 90% of real-world conditional-logic problems.

Why IF is Excel's most important function

Ask ten Excel users to name the single most useful function and IF wins by a landslide. It's the mechanism that turns spreadsheets from calculators into decision engines. Every dashboard, every financial model, every business report has IF somewhere in its DNA — usually in dozens of cells.

The reason is simple: business logic is conditional. "Give the discount only if the order exceeds $1,000." "Send an alert only if the inventory drops below 50." "Show the actual value if it exists, otherwise show a friendly message." Every one of these is an IF statement waiting to be written.

IF has been in Excel since version 1.0 in 1985 — 40 years of continuous existence. It works in every spreadsheet application on earth with identical syntax. Master IF and you have a skill that's transferable across Excel versions, Google Sheets, LibreOffice, Numbers, and every other spreadsheet that will ever exist.

This guide starts with the basics but goes far beyond. By the end you'll understand the entire IF family — IF, IFS, SWITCH, IFERROR, IFNA, AND, OR, NOT — and know exactly which one to reach for in every situation.

IF syntax — the 3 arguments explained

=IF(logical_test, [value_if_true], [value_if_false])

Three arguments, one required. Both value arguments are technically optional but you should always provide both — omitting either creates confusing behavior that's hard to debug.

ArgumentRequired?What it does
logical_test REQUIRED Any expression that evaluates to TRUE or FALSE. Comparisons like A1>100, B1="APAC", function results like ISBLANK(C1), or nested logic with AND/OR.
value_if_true Optional (but include it) What to return when the test is TRUE. Can be a literal value, a cell reference, a formula, or another function call. Omitting it returns 0.
value_if_false Optional (but include it) What to return when the test is FALSE. Same rules as value_if_true. Omitting it returns FALSE literally, which is confusing in most contexts.
The mental model

Read =IF(A1>60, "Pass", "Fail") as: "If A1 is greater than 60, return Pass, otherwise return Fail." IF is a decision — one question, two possible answers. Getting comfortable with this mental model makes every other logical function easier.

10 essential IF patterns

Pattern 1

Simple TRUE/FALSE decision

The starting point. Compare a value to a threshold, return one of two text results:

=IF(A1>=60, "Pass", "Fail")

For A1 = 85, returns "Pass". For A1 = 45, returns "Fail". This pattern powers grading, approval, and any binary classification.

Pattern 2

Return a calculated value, not just text

The value_if_true and value_if_false arguments can be full expressions, not just literals. Apply a bonus rate only above a threshold:

=IF(A1>10000, A1*0.10, A1*0.05)

Sales above $10,000 get 10% bonus, otherwise 5%. The formula itself does the math — no need for a separate calculation cell.

Pattern 3

Text comparison

Comparing text works the same as numbers — just wrap the literal in double quotes:

=IF(A1="APAC", "Regional priority", "Standard priority")

IF is case-insensitive — "APAC" and "apac" test as equal. For case-sensitive comparison, use EXACT inside IF: =IF(EXACT(A1, "APAC"), ...).

Pattern 4

IF with AND — all conditions must pass

Wrap multiple conditions in AND() when EVERY condition needs to be true. Loan approval requires both income AND credit score:

=IF(AND(A1>=60000, B1>=700), "Approved", "Review needed")

AND takes up to 255 conditions. Only if EVERY one is true does the outer IF return "Approved".

Pattern 5

IF with OR — any condition can pass

Wrap in OR() when meeting EITHER condition is enough. Exclude records under 18 OR over 65:

=IF(OR(A1<18, A1>65), "Excluded", "Eligible")

OR fires as soon as any condition is true. Useful for exception handling and edge-case flagging.

Pattern 6

IF with NOT — invert a condition

NOT flips TRUE to FALSE and vice versa. Useful when the natural phrasing of your logic is negative:

=IF(NOT(ISBLANK(A1)), A1*1.1, "No data")

If A1 is NOT blank, apply the calculation. Otherwise show a placeholder message.

Pattern 7

Nested IF — the classic multi-tier

Chain IFs when you have 3+ possible outcomes. Letter grades from a score:

=IF(A1>=90, "A", IF(A1>=80, "B", IF(A1>=70, "C", IF(A1>=60, "D", "F"))))

Each IF's value_if_false is another IF, forming a decision tree. Test the STRICTEST condition first — Excel returns the first match and stops. Get the order wrong and everything above 60 gets a "D".

Pattern 8

IF returning a range for SUM or AVERAGE

IF can return a range, not just a single value. Sum different ranges based on a condition:

=SUM(IF(A1="Q1", B2:B10, C2:C10))

Returns the sum of B2:B10 when A1 is "Q1", otherwise sum of C2:C10. Powerful for conditional aggregation.

Pattern 9

Chained IF for range banding

Classify a numeric value into ranges (small/medium/large):

=IF(A1<100, "Small", IF(A1<500, "Medium", "Large"))

Similar to nested grading. For 3 tiers, nested IF is fine. For 5+ tiers, switch to IFS or a lookup table.

Pattern 10

IF with lookup for dynamic thresholds

Combine IF with VLOOKUP when the threshold itself comes from a table:

=IF(A1 > VLOOKUP(B1, ThresholdTable, 2, FALSE), "Above target", "Below target")

B1 might hold a region code; VLOOKUP finds that region's threshold; IF compares A1 to it. This pattern is how reactive dashboards work.

Nested IF — how deep is too deep

Excel technically allows up to 64 nested IF statements. In practice, anything beyond 5 becomes unreadable and error-prone. There's a saying among Excel developers: "If your formula has more than 3 IFs, you're using the wrong function."

The reasons nested IF gets ugly fast:

Parenthesis counting. Each IF opens a paren; the closing parens all pile up at the end. Miss one and the formula fails with an unhelpful error.

Order dependence. Conditions must be evaluated in a specific order (usually strictest first). Rearranging the wrong way silently breaks the logic.

Hard to modify. Adding a new tier means restructuring the whole formula. Removing a tier requires careful parenthesis management.

Hard to read. A 5-level nested IF looks like =IF(x, a, IF(y, b, IF(z, c, IF(w, d, e)))). Anyone maintaining the workbook has to mentally parse this every time.

The 3-IF rule

If your logic needs more than 3 conditions, don't use nested IF — use IFS (Excel 2016+), SWITCH (for exact matches), or a lookup table with VLOOKUP or XLOOKUP. All three are easier to read, easier to modify, and less error-prone.

IFS — the modern replacement for nested IF

IFS (Excel 2016+) is designed to replace deeply nested IF chains. Same logic, cleaner syntax:

=IFS(condition1, value1, [condition2, value2], ..., [TRUE, fallback])

Compare the grading formula in both styles:

Nested IF (universal):

=IF(A1>=90,"A",IF(A1>=80,"B",IF(A1>=70,"C",IF(A1>=60,"D","F"))))

IFS (Excel 2016+):

=IFS(A1>=90,"A",A1>=80,"B",A1>=70,"C",A1>=60,"D",TRUE,"F")

Same result. IFS drops 4 opening and 4 closing parentheses, reads left-to-right as a flat sequence, and is trivial to modify (add or remove condition-value pairs).

Always end IFS with TRUE, fallback

Without a catch-all, IFS returns #N/A when no condition matches. Ending with TRUE, "default" creates a fallback — TRUE is always true, so this pair fires when nothing above matched. This one habit prevents the most common IFS bug. Full details: IFS function page.

SWITCH — for exact-match branching

SWITCH (Excel 2016+) is specifically for comparing a single value against multiple exact matches. Region-to-shipping-cost mapping:

=SWITCH(expression, value1, result1, [value2, result2], ..., [default])

Shipping costs by region — three approaches:

Nested IF:

=IF(A1="US",5,IF(A1="EU",12,IF(A1="APAC",18,25)))

SWITCH:

=SWITCH(A1, "US",5, "EU",12, "APAC",18, 25)

SWITCH is more compact for exact-match logic because you don't repeat the compared value in every condition. The trailing 25 is the default — like IFS's TRUE, fallback.

When to use SWITCH vs IFS

Use SWITCH when you're comparing ONE value against multiple exact matches: region codes, product SKUs, status strings, error codes.

Use IFS when your conditions involve ranges, math, or different variables per branch: grading by score, tax brackets, tiered pricing.

Use nested IF only if you need backward compatibility with Excel 2013 or older.

AND, OR, NOT — combining conditions

These three functions let you build compound logical tests. All of them can be nested inside IF, IFS, or used standalone (they return TRUE/FALSE).

AND(condition1, condition2, ...)

Returns TRUE only if ALL conditions are true. Up to 255 conditions.

=IF(AND(A1>=60000, B1>=700, C1<=40), "Approved", "Declined")

Requires income ≥ 60k AND credit ≥ 700 AND debt-ratio ≤ 40. Miss any one and the loan is declined.

OR(condition1, condition2, ...)

Returns TRUE if ANY condition is true.

=IF(OR(A1="Urgent", A1="Critical", B1>100), "Escalate", "Normal")

Escalates if priority is Urgent OR Critical OR value exceeds 100.

NOT(condition)

Inverts a boolean. Takes exactly one argument.

=IF(NOT(ISBLANK(A1)), A1*1.1, 0)

Apply the calculation only when A1 is NOT blank. NOT is useful when your natural phrasing is negative.

Nesting AND, OR, and NOT together

Combine them for complex conditions:

=IF(AND(OR(A1="US", A1="CA"), NOT(ISBLANK(B1))), "Process", "Skip")

Read as: "If region is US or CA, AND B1 is not blank, then Process, otherwise Skip." Readable when you keep the layers shallow.

IFERROR — the universal error wrapper

IFERROR (Excel 2007+) catches ANY error and replaces it with a fallback value. The most-used error wrapper by volume:

=IFERROR(value, value_if_error)

Wrap any formula that might error:

=IFERROR(A1/B1, 0)

If A1/B1 fails (e.g., B1 is zero), returns 0 instead of #DIV/0!.

=IFERROR(VLOOKUP(A1, Table, 3, FALSE), "Not found")

Lookup misses return "Not found" instead of #N/A. Cleaner than showing raw error codes to end users.

Don't wrap everything in IFERROR

IFERROR catches ALL error types indiscriminately. A #REF! from a broken cell reference will be silently replaced with your fallback — you'll never know something is broken. Use IFERROR when you have a SPECIFIC error you expect and know exactly what fallback should apply. Otherwise use IFNA or IF+ISERROR for more precise handling. See the Excel Errors Complete Guide.

IFNA — the surgical error wrapper for lookups

IFNA (Excel 2013+) catches ONLY the #N/A error and lets all other errors pass through. Perfect for lookups:

=IFNA(value, value_if_na)

Same VLOOKUP scenario, but only NA errors are caught:

=IFNA(VLOOKUP(A1, Table, 3, FALSE), "Not found")

Missing lookups return "Not found". But if the VLOOKUP has a #REF! because the table was deleted, or #NAME? because of a typo, those errors still show — pointing you at the real bug.

IFERROR vs IFNA — the head-to-head

AspectIFERRORIFNA
Catches which errors?All 9 error typesOnly #N/A
Excel version2007+2013+
Best use caseWhen you truly want any error hiddenLookups — catches misses, exposes real bugs
RiskHides genuine bugsDoesn't handle DIV/0, REF, etc.
RecommendationUse sparinglyDefault choice for lookups
The right default for lookups

For VLOOKUP, XLOOKUP, and INDEX/MATCH, use IFNA. It handles the expected "not found" case (which shows as #N/A) while letting genuine bugs like broken references show through. IFERROR is a bigger hammer that hides too much.

CHOOSE — the underrated alternative

CHOOSE isn't technically a logical function but it often replaces IF chains when your branches are indexed by a number:

=CHOOSE(index_num, value1, [value2], [value3], ...)

Convert a score (0-100) to a letter grade using CHOOSE + math:

=CHOOSE(MIN(5, MAX(1, INT(A1/10)-5)), "F", "D", "C", "B", "A")

Divides the score into decades, clamps to 1-5, uses that as an index into the grade list. Compact once you understand it. Also useful for quarter labels:

=CHOOSE(MONTH(A1)/3+0.7, "Q1", "Q2", "Q3", "Q4")

Decision tree — which function to use

Which IF-family function should I use?

  • One condition, two outcomes → use IF
  • 2-3 conditions in a chain → nested IF is still readable
  • 4+ conditions with ranges (grades, tiers) → use IFS (Excel 2016+)
  • Multiple exact-match cases (regions, codes) → use SWITCH (Excel 2016+)
  • Complex condition requiring ALL conditions true → wrap with AND inside IF
  • Complex condition where ANY of several is enough → wrap with OR inside IF
  • Catch any error and substitute a value → use IFERROR
  • Catch only "not found" errors from lookups → use IFNA
  • 10+ branches or dynamic thresholds → use VLOOKUP or XLOOKUP with a lookup table
  • Branches indexed by a small integer → use CHOOSE
  • Need to work in Excel 2013 or older → nested IF only (IFS/SWITCH unavailable)

Common IF mistakes and fixes

MistakeSymptomFix
Nested IF condition order wrong Every value above the loosest threshold returns the loose result Test STRICTEST condition first. In grading, test >=90 before >=60.
Missing quotes around text #NAME? error Wrap all text literals in double quotes: =IF(A1="APAC", ...) not =IF(A1=APAC, ...).
Comparing text-formatted number to real number Comparison always returns FALSE Use VALUE(A1) to convert text to number, or ensure both sides are the same type.
Trailing spaces breaking equality A1="APAC" unexpectedly returns FALSE Wrap in TRIM: =IF(TRIM(A1)="APAC", ...). Data from web/PDF often has invisible spaces.
Forgotten IFS catch-all Unmatched values return #N/A Always end IFS with TRUE, "default". TRUE is a catch-all that fires when nothing above matched.
Case sensitivity assumed Comparisons ignore case when you expected them to be strict IF is case-insensitive by default. For case-sensitive: =IF(EXACT(A1, "APAC"), ...).
Unbalanced parentheses in nested IF Formula won't accept, or evaluates strangely Count opening and closing parens. Each IF adds one of each. In Excel, matching parens light up briefly when you type them.
Over-nesting for readability Formula becomes unmaintainable at 4+ levels Switch to IFS, SWITCH, or a lookup table. Nested IF beyond 3 levels is a code smell.

Best practices — writing IF formulas that scale

The difference between an IF formula that works today and one that survives 3 years of edits comes down to a handful of habits. Here are the ones that separate professional Excel work from throwaway spreadsheets:

1. Use cell references instead of hardcoded values

Instead of hardcoding thresholds in every formula, put them in named cells and reference them. Compare:

=IF(A1>=1000, A1*0.10, A1*0.05)

vs the maintainable version, with threshold in $E$1 and rates in $E$2 and $E$3:

=IF(A1>=$E$1, A1*$E$2, A1*$E$3)

When the threshold changes from $1,000 to $1,500, you edit one cell instead of hunting through every formula. This is the single highest-leverage habit for any spreadsheet you'll maintain longer than a week.

2. Prefer readability over cleverness

A clever one-line formula that saves 20 characters but takes 5 minutes to understand loses to a longer, boring formula. If your future self (or a colleague) needs to read the workbook, use the more verbose approach:

=IFS(Score>=90,"A", Score>=80,"B", Score>=70,"C", Score>=60,"D", TRUE,"F")

Beats the clever CHOOSE+INT math trick even though it's 20 characters longer. Excel time is cheap; human time is not.

3. Add helper columns instead of mega-formulas

A single 200-character IF+AND+OR+VLOOKUP monster is hard to debug. Split it into 3 helper columns each computing one intermediate value, then a final column that combines them. When something breaks, you can see EXACTLY which step failed.

4. Use LET for repeated subexpressions

If you reference the same computation twice in a formula, use LET (Excel 365) to name it once:

=LET(price, VLOOKUP(A1, Table, 3, FALSE), IF(ISNA(price), "N/A", price * 1.1))

The VLOOKUP runs once, stored as price, then referenced twice. Faster, cleaner, easier to modify. See LET function page.

5. Test edge cases explicitly

For every IF formula, ask: what happens when the input is blank, zero, negative, or text where a number is expected? Build a small test area with edge-case inputs and verify the formula behaves correctly. 30 seconds of testing prevents hours of production debugging.

6. Comment complex logic with a helper cell

Excel doesn't have inline comments in formulas, but you can put an explanation in a nearby cell. Cell E10 has the formula, cell F10 has the text "Bonus rate: 10% above $1,000 threshold, else 5%". Future you (and your team) will thank you.

Once you're fluent with IF, three related function families extend your conditional-logic toolkit:

SUMIF / COUNTIF / AVERAGEIF — aggregation with a condition

Instead of IF returning a single result, SUMIF (and friends) apply a condition across a range and aggregate the matches:

=SUMIF(A2:A100, "APAC", B2:B100)

Sums B2:B100 only where A2:A100 equals "APAC". SUMIFS, COUNTIFS, and AVERAGEIFS handle multiple conditions.

MAXIFS / MINIFS — filtered extremes

Find the max or min value from rows meeting a condition:

=MAXIFS(B2:B100, A2:A100, "APAC")

Returns the largest APAC value. Excel 2019+.

FILTER — return matching rows as an array

Modern Excel's FILTER function returns ALL rows matching a condition as a spilling array:

=FILTER(A2:C100, A2:A100="APAC", "None")

Where IF returns one value based on a condition, FILTER returns a whole set of rows. Two different tools for related jobs. See the Dynamic Arrays Complete Guide for the full modern-Excel context.

Related functions

📥 Download the practice workbook

6 IF patterns · IFS vs SWITCH vs nested IF · IFERROR vs IFNA head-to-head · 24 live formulas

Open Workbook on Drive →

Frequently asked questions

How many nested IFs can Excel handle?

Excel allows up to 64 nested IF statements, but in practice anything beyond 5 levels becomes unmaintainable. If you need more than 3-4 conditions, switch to IFS (Excel 2016+), SWITCH (Excel 2016+), or a lookup table with VLOOKUP or XLOOKUP — all three are easier to read, edit, and debug than deeply nested IF.

What's the difference between IF and IFS?

IF handles one condition with an else clause. IFS handles multiple conditions in a flat sequence — cleaner syntax than nested IF. IFS requires Excel 2016 or newer; nested IF works in every version. For 2 or fewer conditions, use IF. For 3+ conditions on modern Excel, use IFS.

Should I always end IFS with TRUE?

Yes. Without a catch-all, IFS returns #N/A when no condition matches. Ending with TRUE, "default" creates a fallback that fires when nothing above matched. This one habit prevents the most common IFS bug.

When should I use SWITCH instead of IF?

Use SWITCH when comparing a single value to multiple exact matches (e.g. region codes to shipping costs). Use IF or IFS when comparing with ranges or complex conditions. SWITCH is cleaner for exact-value branching; IF is more flexible for numeric ranges and compound conditions.

What's the difference between IFERROR and IFNA?

IFERROR catches all 9 error types (#REF, #NAME, #VALUE, #DIV/0, #N/A, #NULL, #NUM, #SPILL, #CALC). IFNA catches only the #N/A error, letting other errors pass through so you can see genuine bugs. Use IFNA for lookups where missing values are expected but other errors would indicate real problems.

Can IF return a formula instead of a value?

Yes. IF's value_if_true and value_if_false can be any Excel expression — literal values, cell references, calculations, or other function calls. For example, =IF(A1>100, B1*0.9, B1) returns a discounted price only when the condition is met. This is what makes IF so powerful — the branches can do arbitrary work, not just return canned values.

How do I check multiple conditions in one IF?

Wrap the conditions in AND() (all must be true) or OR() (any must be true). Example: =IF(AND(A1>=60000, B1>=700), "Approved", "Review") requires both income and credit score to pass. NOT() inverts a condition. You can nest AND, OR, and NOT together for complex logic like =IF(AND(OR(A1="US", A1="CA"), NOT(ISBLANK(B1))), ...).

Why does my IF return the wrong result?

Common causes: (1) comparing text with different capitalization or trailing spaces — use TRIM and be aware IF is case-insensitive, (2) comparing text-formatted numbers with real numbers — use VALUE() to convert, (3) getting nested IF condition order wrong — always test from strictest to loosest, (4) missing quotation marks around text values. See the full Excel Errors Complete Guide for debugging techniques.

Is IF case-sensitive?

No — by default IF treats "APAC" and "apac" as equal. For case-sensitive comparison, wrap in EXACT: =IF(EXACT(A1, "APAC"), "Match", "No match"). EXACT returns TRUE only if strings match exactly including case.

· · ·

Master IF and its family, and you've mastered Excel's decision-making core. Every dashboard, model, and report you'll ever build relies on this foundation.