IF Function in Excel: Complete Guide with Examples
Complete guide to the Excel IF function: syntax, nested IF, IFS, IF with AND/OR, IFERROR, and practical examples for every skill level.

The IF function is the gateway to logical thinking in Excel. Before IF, a spreadsheet is essentially a calculator — you enter numbers, apply formulas, get results. After IF, the spreadsheet can make decisions. It can look at a value, compare it against a condition, and return different outputs depending on what it finds.
That transition from passive calculation to active logic is what makes IF one of the most foundational functions in the application, and one that every Excel user encounters within the first few weeks of real work. The if function excel users depend on operates on a simple three-part structure that expands into almost unlimited flexibility.
The basic syntax is: =IF(logical_test, value_if_true, value_if_false). The logical_test evaluates to either TRUE or FALSE. When it's true, the function returns the value_if_true. When it's false, it returns the value_if_false. A simple real-world example: =IF(B2>=70, "Pass", "Fail") checks whether a score in B2 meets the passing threshold. If the score is 70 or above, the cell shows Pass. If it's below 70, it shows Fail. That's the complete logic in one compact formula.
The logical_test supports all six comparison operators: greater than (>), less than (<), equal to (=), not equal to (<>), greater than or equal to (>=), and less than or equal to (<=). These operators work with numbers, text, dates, and cell references. Comparing text is case-insensitive by default — =IF(A1="yes", 1, 0) matches "YES", "yes", and "Yes" equally. If you need case-sensitive matching, use EXACT inside the test: =IF(EXACT(A1,"YES"), 1, 0) returns 1 only for uppercase YES.
The return values in the second and third positions are equally flexible. You can return text strings, numbers, formulas, cell references, or even other functions. =IF(C3>0, C3*0.15, 0) calculates a 15% commission on positive sales and returns zero for everything else. =IF(D2
Dates work naturally in IF logic because Excel stores them as serial numbers. =IF(A2
One behavior that catches new users off guard: in Excel, the number 0 evaluates as FALSE in a logical context, and any non-zero number evaluates as TRUE. This means =IF(COUNTIF(A:A,"Error"), "Errors found", "Clean") works as expected — COUNTIF returns a count (0 or greater), and IF treats 0 as FALSE and any positive number as TRUE. Similarly, empty cells evaluate as 0 (FALSE) in numeric comparisons but as an empty string in text comparisons. Understanding these edge cases prevents a category of subtle bugs that produce wrong results without generating visible errors.
The value_if_false argument can be an empty string ("") to make the cell appear blank when the condition is not met. =IF(B3>0, "Invoice due", "") leaves the cell empty rather than showing a FALSE or zero when there's no invoice. This is especially useful in templates and dashboards where you want clean visual output rather than a grid full of "FALSE" labels in rows where the condition hasn't triggered.
Referencing other cells and ranges within the return values enables IF to drive formatting, labeling, and calculation workflows simultaneously. =IF(A2>MAX(A:A)*0.9, "Top 10%", "Standard") labels records that fall within 10% of the column maximum — the threshold adjusts automatically as data changes. =IF(B2=MIN(B:B), "Lowest cost", "") marks the minimum value in a list dynamically. These patterns are what make Excel dashboards genuinely interactive rather than static snapshots that require manual updates every time underlying data changes.
Combining IF with ISBLANK, ISNUMBER, and ISTEXT guards downstream formulas against unexpected inputs. =IF(ISBLANK(C2), "", C2*D2) prevents a multiplication formula from running on empty rows, which would otherwise fill the column with zeros that distort averages and totals. =IF(ISNUMBER(A2), A2*1.1, A2) applies a markup only when the cell actually contains a number, leaving text entries unchanged. These defensive patterns are standard practice in production templates that will be used by people who didn't build them and won't behave predictably with the data.
=IF(logical_test, value_if_true, value_if_false)
- logical_test — any expression that evaluates to TRUE or FALSE (e.g., A1>100, B2="Yes", C3<>0)
- value_if_true — what to return when the test is TRUE (text, number, formula, or cell reference)
- value_if_false — what to return when the test is FALSE (can be another IF for nesting, or "" for blank)
Example: =IF(Score>=60, "Pass", "Fail")
IF Function Variations
=IF(A1>100, "Over", "Under") — evaluates a single condition and returns one of two values. Handles text, numbers, dates, and logical values.
=IF(A1>=90, "A", IF(A1>=80, "B", "C")) — chains multiple conditions. Place conditions highest-to-lowest threshold. Supports up to 64 nesting levels.
=IFS(A1>=90, "A", A1>=80, "B", TRUE, "C") — evaluates multiple conditions without nesting. Cleaner syntax; available in Excel 2019 and 365.
=IF(AND(A1>0, B1>0), "Both positive", "No") — AND requires all conditions true; OR requires any one condition true. Combine for complex multi-dimensional logic.

Nested IF functions extend the single-condition structure into multi-condition decision trees. The syntax nests one IF inside the value_if_false position of another: =IF(A1>=90, "A", IF(A1>=80, "B", IF(A1>=70, "C", IF(A1>=60, "D", "F")))). This evaluates conditions left to right — if A1 is 90 or above, return A; otherwise check 80 for B; otherwise check 70 for C; otherwise check 60 for D; otherwise return F. The order matters: conditions must run from highest threshold to lowest because as soon as one condition is true, the remaining conditions are skipped.
Excel's modern limit is 64 nesting levels, but practical readability breaks down around 4 or 5. Deep nesting is technically possible but produces formulas that are almost impossible to audit when something goes wrong six months after you wrote them. At 4+ conditions, the IFS function is the cleaner choice.
IFS evaluates multiple conditions without nesting: =IFS(A1>=90, "A", A1>=80, "B", A1>=70, "C", A1>=60, "D", TRUE, "F"). The TRUE at the end acts as a catch-all else condition — it always evaluates to true, so it captures every case that didn't match an earlier condition. IFS is available in Excel 2019, Excel 365, and current Google Sheets versions.
Combining IF with AND tests whether multiple conditions are all true simultaneously: =IF(AND(A1>0, B1>0), "Both positive", "At least one is not positive"). The AND function returns TRUE only when every argument inside it is true. =IF(AND(Score>=60, Attendance>=80), "Eligible", "Ineligible") requires both conditions to pass. OR works the opposite way — returns TRUE when any one argument is true: =IF(OR(Status="Approved", Manager="VP"), "Proceed", "Hold") proceeds when either approval condition is satisfied.
You can combine AND and OR in a single IF statement for complex multi-dimensional logic: =IF(AND(Revenue>Budget, OR(Region="North", Region="South")), "On track", "Review"). This returns "On track" only when revenue exceeds budget AND the region is either North or South. While this is perfectly valid syntax, nested AND/OR combinations beyond two levels benefit from being broken into helper column formulas for readability — a formula that takes three readings to understand is a formula that will be misread eventually.
Arrays extend IF to work across entire ranges at once. In Excel 365, entering =IF(A1:A10>50, "Pass", "Fail") in a single cell spills results automatically across ten rows. In older Excel versions, the same formula works when entered with Ctrl+Shift+Enter (legacy CSE array entry), displayed with curly braces: {=IF(A1:A10>50, "Pass", "Fail")}. Either way, each element of the range is evaluated independently. This eliminates copying formulas down a column when the same condition applies to the entire dataset, and it prevents the drift errors that occur when a cell in the middle of a manual copy-down gets accidentally deleted or modified.
The SWITCH function is an alternative to nested IF when you're mapping specific values rather than testing ranges. =SWITCH(A1, "Q1", "January–March", "Q2", "April–June", "Q3", "July–September", "Q4", "October–December", "Unknown") maps exact values to outputs without comparison operators. Where nested IF needs >=, <=, or = to test each value, SWITCH simply matches. When you're translating codes, abbreviations, or status values into full descriptions, SWITCH is cleaner than nested IF because you can see both the input value and its output in a readable paired sequence. For range-based logic (greater than, less than), if function excel constructs using IF or IFS remain the better choice.
Circular reference errors occasionally appear when IF formulas reference the cell they're entered in. Excel normally prevents circular references, but some iterative calculation scenarios require them intentionally. Under File → Options → Formulas, enabling "Enable iterative calculation" allows formulas to recalculate a set number of times — useful for accumulating values in running totals where each row references the previous result. This is an advanced pattern; most IF circular reference errors are unintentional and should be resolved by restructuring the formula to reference a different cell rather than enabling iteration, which can cause unintended recalculation behavior across the entire workbook.
IF Function by Use Case
Grade calculations are the classic IF tutorial exercise because they involve ordered threshold comparisons. A full grading formula: =IF(A1>=90, "A", IF(A1>=80, "B", IF(A1>=70, "C", IF(A1>=60, "D", "F")))). Conditions run from highest to lowest — testing >=60 first would return D for everything above 60 before the higher thresholds got a chance to evaluate. IFS handles this more cleanly: =IFS(A1>=90, "A", A1>=80, "B", A1>=70, "C", A1>=60, "D", TRUE, "F").
Weighted grade calculations combine IF with multiplication: =IF(AssignmentType="Final", Score*0.4, Score*0.1) applies different weights based on the assignment category. These patterns generalize to any performance rating system — employee evaluations, quality control scoring, or satisfaction survey categorization all follow the same threshold-to-label mapping structure.

Excel IF Function Reference
Error handling is where IFERROR earns its place in nearly every production spreadsheet. The function wraps any formula and intercepts errors, returning a specified alternative value instead. Syntax: =IFERROR(formula, value_if_error). When the wrapped formula returns a result normally, IFERROR passes it through unchanged. When it returns an error — any of the seven Excel error types (#N/A, #VALUE!, #DIV/0!, #NULL!, #NUM!, #REF!, or #NAME?) — IFERROR returns the fallback value you specify instead. =IFERROR(A1/B1, 0) returns the division result when B1 is non-zero, and returns 0 when B1 would cause #DIV/0!.
VLOOKUP formulas paired with IFERROR are one of the most common patterns in data reconciliation: =IFERROR(VLOOKUP(D2, A:B, 2, FALSE), "Not found") retrieves the matching value from the table when the lookup key exists and returns "Not found" when it doesn't. This prevents the #N/A errors that accumulate when lookup tables have gaps or when you're comparing two lists that don't have identical keys. The result is a clean, readable output column instead of a mix of values and error codes that requires manual filtering before analysis.
IFNA is a more precise alternative to IFERROR specifically for the #N/A error. Using =IFNA(VLOOKUP(D2, A:B, 2, FALSE), "Not found") instead of IFERROR provides different behavior for other error types. If your VLOOKUP produces a #VALUE! error because a data type mismatch exists, IFERROR would hide it — returning "Not found" even though the real problem is malformed data. IFNA lets that #VALUE! error surface so you can fix the underlying issue, while still gracefully handling the expected "key not in table" case. This distinction matters in audit environments where data quality problems need to be surfaced, not masked.
Combining IF with COUNTIF creates conditional counting patterns useful in dashboards and status boards: =IF(COUNTIF(B:B,"Open")>0, "Active items", "All closed") checks whether any open items exist without specifying how many. More specifically, =IF(COUNTIF(B:B,"Overdue")>5, "ESCALATE", "Normal") triggers an escalation flag when overdue counts exceed a threshold. For financial reporting, combining IF with SUMIF handles conditional subtotals: =IF(SUMIF(A:A,"Marketing",C:C)>Budget, "Over", "Under") compares Marketing's actual spend against budget. These if function excel patterns form the core of automated dashboard updates that eliminate manual status reporting.
Debugging IF functions follows a systematic process that saves time compared to random formula edits. Start by isolating the logical_test: copy just that part of the formula into a blank cell and verify it returns TRUE or FALSE as expected for your test data. Then verify the value_if_true and value_if_false expressions independently. This identifies whether the problem is in the condition test or in what the formula does when the condition is met.
The Evaluate Formula tool (Formulas ribbon → Formula Auditing → Evaluate Formula) steps through each calculation interactively, showing you the result of each component in sequence. For nested IF problems, this tool is faster than any other debugging approach because it shows exactly where the logic diverges from your expectation.
Best practices for maintaining IF formulas in shared workbooks come down to three principles: name your ranges so conditions read like sentences, add a comment to any non-obvious logical test explaining the business rule it represents, and document the expected range of input values for each condition. A formula that reads =IF(GrossMargin
Version compatibility deserves attention in shared or cross-organization workbooks. IFS, XLOOKUP, and dynamic array IF behavior are available only in Excel 2019, 2021, or 365. If your workbook will be opened in Excel 2016 or older, these functions either return errors or lose their spill behavior. When compatibility is a concern, stick to nested IF for multi-condition logic and enter array IF formulas with Ctrl+Shift+Enter for range-based operations. Excel's Compatibility Checker (File → Info → Check for Issues → Check Compatibility) identifies functions in your workbook that older versions can't handle and flags them before sharing.

Version compatibility: The basic IF function works in all Excel versions and Google Sheets. IFS requires Excel 2019+ or Excel 365. Dynamic array spill behavior (entering IF once for a full column) requires Excel 365. XLOOKUP requires Excel 365 or Excel 2021. If your workbook needs to run in Excel 2016 or earlier, use nested IF for multi-condition logic and Ctrl+Shift+Enter for range-based IF formulas. Check File → Info → Check for Issues → Check Compatibility before sharing workbooks with users on older Excel versions.
The practical ceiling of what IF can accomplish on its own is lower than most users initially assume. When logic involves more than five or six conditions, or when you're mapping specific input values to outputs rather than testing ranges, alternative approaches become more maintainable.
A lookup table with VLOOKUP or XLOOKUP handles value mapping more cleanly than ten nested IFs — it's easier to update (add a row to the table), easier to audit (the logic is visible in the table, not buried in formula syntax), and easier to explain to stakeholders. Recognizing when IF is the right tool versus when a different approach would serve better is a genuine Excel proficiency milestone.
For complex business rule automation, combining IF with named ranges and table references produces formulas that survive workbook updates and user edits better than formulas built with direct cell references. A formula that tests against a named range called "ApprovalThresholds" rather than against a specific cell address continues to work correctly even if rows are added above the reference cell.
Structuring IF-based logic to reference named constants and table columns rather than absolute cell addresses is the difference between formulas that work reliably in a shared workbook and formulas that break silently when a colleague adds a row to the wrong place.
The evolution from basic IF to IFS to XLOOKUP to LAMBDA (in Excel 365) represents the full spectrum of Excel's conditional logic capabilities. IF remains the foundation — fast to write, universally understood, and sufficient for the majority of conditional requirements. The higher-level functions exist to handle the edge cases where IF's simplicity creates complexity. Learning when to use each tool, rather than defaulting to the familiar one for every situation, is what separates intermediate Excel proficiency from genuine advanced competency in the platform.
For users learning Excel systematically, mastering IF unlocks a path to the broader logical function family: IF → nested IF → IFS → IF with AND/OR → IFERROR/IFNA → conditional aggregation (SUMIF, COUNTIF, AVERAGEIF) → array formulas → XLOOKUP → LAMBDA. Each step adds capabilities that the previous one couldn't handle cleanly. The IF function is both the entry point and the recurring reference point throughout that progression — you'll come back to it constantly even as you add more advanced tools to your workflow.
IF Function Best Practices
- ✓Test logical_test independently in a blank cell — confirm it returns TRUE or FALSE as expected
- ✓Order nested IF conditions highest-to-lowest threshold (never lowest-to-highest)
- ✓Use IFS instead of deeply nested IF when testing 4+ conditions
- ✓Prefer IFNA over IFERROR for VLOOKUP results — it's more precise and surfaces real errors
- ✓Name ranges for clarity: =IF(Revenue>Budget) reads better than =IF(C47>D47)
- ✓Use "" (empty string) in value_if_false when you want blank output instead of FALSE or 0
- ✓Break complex AND/OR combinations into helper columns for readability and debugging
- ✓For value-based mapping (codes to descriptions), use SWITCH or XLOOKUP instead of nested IF
IF vs. Alternative Functions
- +Universal compatibility — works in every Excel version and Google Sheets without version concerns
- +Extremely flexible — returns text, numbers, formulas, dates, or functions as output values
- +Familiar syntax that any Excel user can read and audit without documentation
- +Chains cleanly with AND, OR, IFERROR, COUNTIF, SUMIF, and all logical functions
- +Dynamic array support in Excel 365 applies to entire columns in a single formula
- −Deep nesting (5+ levels) becomes hard to read, debug, and maintain over time
- −IFS is cleaner for 4+ conditions but requires Excel 2019 or later
- −Value-mapping logic is more maintainable as a lookup table with XLOOKUP
- −Legacy CSE array entry (Ctrl+Shift+Enter) required in pre-365 Excel for range-based IF
Excel Questions and Answers
About the Author
Attorney & Bar Exam Preparation Specialist
Yale Law SchoolJames R. Hargrove is a practicing attorney and legal educator with a Juris Doctor from Yale Law School and an LLM in Constitutional Law. With over a decade of experience coaching bar exam candidates across multiple jurisdictions, he specializes in MBE strategy, state-specific essay preparation, and multistate performance test techniques.