IF — The Foundation of Excel Logic
Every Excel user's first "real" formula. Check a condition, return one value if true, another if false. Simple in principle, endlessly composable in practice — the primitive underneath IFERROR, IFS, SUMIFS, COUNTIFS, and every conditional formatting rule. Universal support since Excel 1.0. Up to 64 levels of nesting.
=IF(A2>100, Big, Small) fails because Excel treats Big and Small as named ranges (and returns a NAME error). Correct: =IF(A2>100, "Big", "Small"). Numbers and cell references do NOT need quotes.
Syntax breakdown
IF has three arguments — a logical test and two possible return values. The third is technically optional but almost always specified.
| Argument | Type | What it does |
|---|---|---|
logical_test |
REQUIRED | Any expression that evaluates to TRUE or FALSE. Comparisons (A2>100), cell contents (A2="Yes"), function results (ISBLANK(A2)), or compound conditions (AND(...), OR(...)). |
value_if_true |
REQUIRED | What IF returns when the test is TRUE. Can be text (in quotes), a number, a cell reference, or another formula — including another IF for nesting. |
value_if_false |
OPTIONAL | What IF returns when the test is FALSE. If omitted, IF returns FALSE (the literal boolean, which usually looks wrong). Always specify this argument for clarity. |
= (equals), <> (not equals), > (greater than), < (less than), >= (greater or equal), <= (less or equal). Text comparisons are case-insensitive — "North" and "NORTH" match. For case-sensitive matching, use EXACT().
Five working examples
Every example uses the same 24-row sales log as the IFS family. Q1 2026 data: grand total $125,441.65, grand max $13,350, grand min $1,300.
01 Basic IF — pass/fail on a threshold
Tag each transaction as "Big deal" or "Standard" based on a single threshold.
| Date | Salesperson | Amount | IF Tag |
|---|---|---|---|
| Jan 26 | Emma Thompson | $11,570.00 | Big deal |
| Jan 30 | David Kim | $9,675.00 | Big deal |
| Feb 3 | Sofia Rodriguez | $2,275.00 | Standard |
| Feb 27 | Michael Chen | $3,749.85 | Standard |
| Mar 22 | Michael Chen | $13,350.00 | Big deal |
| Mar 26 | Aisha Patel | $1,300.00 | Standard |
This is the foundation. Every IF variant on this page builds on the same shape: check something, return one of two things.
02 IF with AND / OR — compound conditions
When you need multiple criteria to jointly hold (or any one to hold), wrap them in AND() or OR() inside the logical test.
Pattern A — AND (all must match)
Pattern B — OR (any can match)
Pattern C — Nested combination
=IF(C2="North", IF(F2>5000, "Priority", ""), ""). But AND reads more naturally, has fewer parens to count, and matches how the requirement is spoken: "North AND above 5000."
03 Nested IF — multi-tier assignment
When you need MORE than two outcomes, IF statements nest inside each other's value_if_false slot.
| Tier | Threshold | Count | Examples |
|---|---|---|---|
| Platinum | ≥ $10,000 | 3 | $11,570 · $10,680 · $13,350 |
| Gold | ≥ $7,000 | 6 | $8,900 · $9,675 · $7,120 · $8,600 · $7,525 · $9,250 |
| Silver | ≥ $4,000 | 1 | $6,450 |
| Bronze | < $4,000 | 14 | everything else |
04 IF vs IFS — the modern replacement
Same tier logic written two ways. IFS() shipped with Excel 2019 as a cleaner alternative to deeply nested IF.
Method 1: Nested IF (works everywhere)
Method 2: IFS (Excel 2019+)
Both produce identical results across all 24 rows. The workbook proves it with a side-by-side comparison and a =IF(E2=F2,"✓","MISMATCH") verification column.
TRUE in IFS doesTRUE as the last condition. TRUE always matches, so it becomes the default. Without it, an unmatched row returns the #N/A error. This is IFS's most common bug for new users.05 IFERROR wrap — the protective clause
Wrap any formula that could break with IFERROR to replace errors with a fallback value.
Division by zero
Lookup that might fail
IFERROR chain (advanced)
Interactive playground
Try it Live IF demonstration
Mirrors live cells from the workbook. Edit the yellow input, watch the blue result update.
Download the workbook to try the Decision Tree sheet — edit an amount and watch the nested IF resolve.
The nested IF decision tree
Nested IF is the concept most beginners struggle with. Here's exactly how Excel reads the tier formula from Example 3 — one check at a time, left to right, top to bottom:
How Excel reads the nested IF
The IF cheat sheet — 10 patterns for daily use
Copy any of these, adapt the ranges to your data, and you're 80% of the way there. Same 10 patterns are in the workbook's Cheat Sheet sheet:
10 patterns you'll use every day
From simplest (threshold check) to combinatorial (IF with a SUMIFS inside). Every one is a copy-paste starting point.
IF(A2<>"Done",...)IF vs IFS — a side-by-side
Same logic, two ways. When should you reach for IFS instead of nesting IF?
| Aspect | Nested IF | IFS (Excel 2019+) |
|---|---|---|
| Excel version | Every version (since 1.0) | 2019, 2021, 365 · older versions error out |
| Syntax (3 tiers) | IF(A>=10000,"P",IF(A>=7000,"G","B")) | IFS(A>=10000,"P",A>=7000,"G",TRUE,"B") |
| Closing parens | 3 nested — easy to miscount | 1 — always |
| Default / "else" | Built-in via value_if_false | Need TRUE as last condition |
| Readability at 5+ tiers | Poor — deeply indented | Good — reads like a table |
| Best for 5+ tiers | Use VLOOKUP against a tier table instead | Use VLOOKUP against a tier table instead |
Common errors and how to fix them
IF itself rarely errors — but the expressions inside it can. Six common scenarios:
| Result | Why it happens | Broken → Fix |
|---|---|---|
| NAME error | Text output missing quotes — Excel treats bare words as named ranges. | =IF(A2>100, Big, Small)
=IF(A2>100, "Big", "Small") |
| FALSE (literal) | Omitted value_if_false — Excel returns the boolean FALSE. | =IF(A2>100, "Big")
=IF(A2>100, "Big", "Small") |
| Always TRUE | Trailing space in text comparison causes mismatch. | =IF(A2="North",1,0) but A2 has trailing space
=IF(TRIM(A2)="North",1,0) |
| Wrong tier | Nested IF thresholds in wrong order — first match wins. | =IF(A>=4000,"Silver",IF(A>=10000,"Platinum",...))
=IF(A>=10000,"Platinum",IF(A>=4000,"Silver",...)) |
| VALUE error | Comparing text to number without explicit conversion. | =IF(A2>"100", ...) // A2 is text
=IF(VALUE(A2)>100, ...) |
| Broken paren count | Deep nested IF has mismatched parentheses. | =IF(A>10,IF(B>5,"P","Q","R")
=IF(A>10,IF(B>5,"P","Q"),"R") |
IF is the primitive underneath everything
Companion functions worth knowing
<>.The IFS family — conditional aggregators built on IF's logic
Excel version compatibility
IF works in every version of Excel ever shipped, and in every spreadsheet clone:
| Platform | Supports IF? | Notes |
|---|---|---|
| Excel 365 (Windows & Mac) | ✓ Yes | Full support |
| Excel 2021 / 2019 / 2016 / 2013 | ✓ Yes | Full support |
| Excel 2010 / 2007 / 2003 | ✓ Yes | Full support |
| Excel 2000 / 97 / 95 / 5 / 4 / 3 / 2 / 1 | ✓ Yes | Been in Excel since day one |
| Excel for the web | ✓ Yes | Full support |
| Excel on iPad & iPhone | ✓ Yes | Full support |
| Google Sheets | ✓ Yes | Same syntax, same behavior |
| LibreOffice Calc | ✓ Yes | Full support |
| Apple Numbers | ✓ Yes | Full support |
When to use IF vs. alternatives
Use IF when…
- You have exactly 2 possible outcomes. True path, false path. Done.
- You have 3 outcomes and need cross-version support. Nested IF works everywhere.
- You're wrapping any formula in IFERROR. That's IFERROR = specialized IF.
Use IFS instead when…
- You have 3-5 outcomes AND you're on Excel 2019+.
- Readability matters (dashboards, shared workbooks).
Use VLOOKUP or INDEX/MATCH instead when…
- You have 5+ outcomes based on a numeric range. A lookup table is cleaner.
- The mapping might change — a lookup table is editable without touching formulas.
Use SWITCH instead when…
- You're matching ONE cell against a list of fixed values (not ranges). SWITCH is designed for that.
Use the IFS siblings (SUMIFS etc.) when…
- You're aggregating values from rows that match criteria. Don't wrap IF around SUMPRODUCT — use SUMIFS directly.
How IF actually works
The algorithm
IF evaluates the logical test to a boolean (TRUE or FALSE). If TRUE, it returns whatever's in the second argument. If FALSE, it returns whatever's in the third argument (or FALSE if the third is omitted). Only ONE of the two branches is evaluated — a critical optimization.
Short-circuit evaluation
Excel does NOT evaluate the un-taken branch. This means =IF(B2=0, "Zero", A2/B2) is safe from divide-by-zero errors — when B2 is 0, the division is never attempted. This short-circuit behavior lets you use IF as a guard clause without extra IFERROR wrapping.
Type coercion
- Booleans: TRUE = 1, FALSE = 0. So
=IF(A2, ...)is TRUE for any non-zero value in A2. - Empty cells: read as 0 for numeric contexts, "" for text.
=IF(A2="", ...)is TRUE for blank cells. - Numbers as text:
"5"and5are NOT equal. UseVALUE()to convert text-numbers.
Nesting limits
Excel 2007+ allows up to 64 nested IFs. If you're approaching that limit, stop — you're building something unmaintainable. Refactor into a lookup table or use IFS.
Performance notes
IF is essentially free at any reasonable scale. Two considerations for extreme cases:
- Volatile functions in un-taken branches. Even though IF short-circuits, if you have
=IF(A2, TODAY(), 0)across 100,000 rows, TODAY() is still volatile — the whole column recomputes on every recalc. Not IF's fault, but common with IF. - Deep nesting. 20-level nested IF calculates 20 times slower than a single-level VLOOKUP against a 20-row tier table. Use lookup tables for many tiers.
When to switch to a lookup table
If your nested IF exceeds 5 levels, refactor to a two-column tier table and use VLOOKUP or INDEX/MATCH. Editing thresholds becomes trivial, the formula becomes readable, and performance improves.
How to write an IF from scratch
-
Write the question
What are you checking? "Is the deal above 5000?" "Is the region North?" State it clearly before you touch the formula.
-
Write the logical test
Translate the question to a comparison. "Above 5000" becomes
A2>5000. This goes in the first argument slot. -
Add value_if_true — the "YES" answer
What should IF return when the test passes? Text (in quotes), a number, or another formula.
-
Add value_if_false — the "NO" answer
Even if you'd default to blank, always specify
""for clarity. Never rely on the implicit FALSE return. -
For 3+ outcomes, replace value_if_false with another IF
The "no" answer becomes the next check. Order from most-specific (highest threshold) to most-general (default).
Functions used with IF
Frequently asked questions
What's the difference between IF and IFS?
IF handles one condition (with an implicit "else"). IFS handles multiple conditions in one formula — no nesting required. IFS shipped with Excel 2019; older versions return a NAME error. IFS reads cleaner at 3-5 conditions but requires TRUE as the last condition to act as the default.
How deep can I nest IF statements?
Excel 2007+ allows up to 64 levels of nesting. Excel 2003 and earlier maxed at 7 levels. Anything above 5 levels is a code smell — refactor to IFS, VLOOKUP against a lookup table, or SWITCH.
Why does my IF return FALSE instead of my value?
You omitted the value_if_false argument. When the logical test is FALSE and no third argument exists, IF returns the literal boolean FALSE. Always specify all three arguments — use "" for a blank result if that's what you want.
Can IF return a formula instead of a value?
Yes — either branch can be a formula, a cell reference, or a function call. =IF(A2>0, SUM(B:B), AVERAGE(C:C)) works. Only the taken branch is evaluated (short-circuit).
Is IF case-sensitive for text comparisons?
No — "North", "NORTH", and "north" all match in an IF comparison. For case-sensitive comparisons, wrap with EXACT: =IF(EXACT(A2, "North"), ...).
Why does IF give a NAME error?
Almost always because a text output isn't in quotes. =IF(A2>100, Yes, No) fails because Excel treats Yes and No as named ranges (which don't exist). Correct: =IF(A2>100, "Yes", "No").
Can IF check for text in a specific position?
Yes — combine IF with SEARCH or FIND: =IF(ISNUMBER(SEARCH("Pro", A2)), "Premium", "Standard"). SEARCH returns a position number for matches, an error otherwise, so ISNUMBER cleanly converts to TRUE/FALSE.
How do I write "IF this cell is blank"?
Three options: =IF(A2="", ...), =IF(ISBLANK(A2), ...), or =IF(LEN(A2)=0, ...). ISBLANK is strictest — it's FALSE for cells with formulas that return "". Use ="" for the "looks blank to the user" check.
What's the difference between IF and IFERROR?
IF checks a condition YOU write. IFERROR checks whether a formula produced an error. Use IFERROR to gracefully handle expected failures (missing lookup, zero denominator) without a manual condition check.
Does IF work in Google Sheets?
Yes, identically. Google Sheets, LibreOffice Calc, and Apple Numbers all implement IF with the same syntax and semantics as Excel.
Can I use IF with dates?
Yes — dates are stored as numbers internally, so any comparison works. =IF(A2>=DATE(2026,1,1), "This year", "Older"). Use DATE(y,m,d) to write literal dates, or reference a cell containing a date.
Which templates use IF?
All 10 of our templates use IF somewhere — it's the foundation of conditional logic. Prominently: Budget Tracker (over/under budget flags), Expense Report (policy compliance checks), Sales Dashboard (target-hit indicators), KPI Dashboard (traffic-light status), Invoice (payment status), Loan Calculator (early-payoff logic), Timesheet (overtime detection), Attendance (present/absent tags), Inventory Tracker (reorder alerts), and Project Timeline (deadline status).
Templates that use IF
Every one of our 10 templates uses IF — it's the foundation of conditional logic:
Skip the syntax. Ask in plain English.
The Sheets & Cells AI Add-in writes IF, nested IF, IFS, IFERROR, and every combination in between — right inside Excel. Type "flag deals above 5000 in North as Priority" and get the working formula, ready to paste.
Try the AI Add-in →