Nested IF and Formula: How to Combine Conditions in Excel

Formulas & functions · Updated November 23, 2026

Nested IF is a formula that places one IF function inside another IF function’s value_if_true or value_if_false argument, letting you test multiple conditions in a single cell. For example, =IF(A1>90,"A",IF(A1>80,"B","C")) returns “A” if A1 is over 90, “B” if over 80, and “C” otherwise.

What Is a Nested IF?

In Excel, the IF function checks a condition and returns one value if true and another if false. A nested IF extends this by replacing either the true or false branch with another IF. This creates a decision tree that evaluates conditions in the order you write them. The formula stops at the first condition that is true, so the order matters. For instance, =IF(A1>=90,"A",IF(A1>=80,"B",IF(A1>=70,"C","F"))) tests high to low. If you reversed the order, a score of 95 would incorrectly return “F” because the first condition would be false.

How to Write a Nested IF Formula

Start with the outer IF, then insert the next IF into the false branch (or true branch if needed). Use commas to separate arguments and close each IF with a closing parenthesis. For example, with a score in cell B2, to assign a letter grade:

  • Click the cell where you want the result.
  • Type =IF(B2>=90,"A",IF(B2>=80,"B",IF(B2>=70,"C","F"))).
  • Press Enter.

Excel evaluates from left to right. If B2 is 85, the first condition (85>=90) is false, so it moves to the second IF; 85>=80 is true, so it returns “B”. The formula works in Excel 365, Excel 2021, and older versions.

When to Use Nested IF vs. IFS

Excel 2016 and later include the IFS function, which is simpler for many conditions: =IFS(B2>=90,"A",B2>=80,"B",B2>=70,"C",TRUE,"F"). IFS tests each condition in order and returns the value for the first true one. Use IFS when you have many conditions and you are using Excel 2016 or newer. Nested IF is still needed if you must run different calculations in the true/false branches, or if you are sharing the file with users on older Excel versions. For example, a nested IF can apply a different bonus rate based on region and sales: =IF(A2="East",B2*0.1,IF(A2="West",B2*0.15,B2*0.05)). IFS cannot do that because it only returns a value, not a calculation based on the condition.

Common Mistakes and How to Fix Them

The most frequent errors are mismatched parentheses and wrong condition order. Excel shows a green triangle if it detects an inconsistent formula, but it will not always catch logic errors. To avoid problems:

  • Count parentheses: each IF opens one and closes one. Use the formula bar’s color coding to see matching pairs.
  • Test with known values. For the grade example, try 95, 85, 75, and 65 to confirm each branch.
  • Use the Evaluate Formula tool (Formulas tab > Formula Auditing > Evaluate Formula) to step through the logic.
  • Remember that text values need double quotes, numbers do not.

Another common issue is using AND or OR inside IF unnecessarily. For example, =IF(AND(A1>0,A1<10),"Yes","No") is fine, but you can often simplify with nested IFs or IFS.

Alternatives to Nested IF: CHOOSE, LOOKUP, and Boolean Logic

For many real-world tasks, other functions are cleaner. The CHOOSE function picks a value from a list by index: =CHOOSE(A1,"Low","Medium","High") returns “Low” if A1 is 1, “Medium” if 2, and so on. VLOOKUP or XLOOKUP can map scores to grades using a lookup table, which is easier to maintain. For example, create a table with scores in column E and grades in column F, then use =XLOOKUP(B2,E2:E5,F2:F5,,-1) to find the grade for a score. Boolean logic can also replace nested IFs: =(A1>90)*"A"&"" is not recommended because it returns 0 for false, but you can combine conditions with multiplication to create numeric results. For text results, nested IF or IFS is more readable.

Performance and Limits

Older Excel versions (2003 and earlier) limited nested IF to 7 levels. Modern Excel allows up to 64 nested IFs, but that is rarely practical. Each additional level makes the formula harder to read and debug. Excel 365’s IFS and SWITCH functions are designed for many conditions and are easier to maintain. If you find yourself nesting more than 5 or 6 IFs, consider using a lookup table or the IFS function. For large datasets, nested IFs are not significantly slower than IFS, but complex formulas can make calculation time noticeable if used thousands of times. Keep formulas simple and use helper columns when necessary.

Frequently Asked Questions

Can I use text and numbers in the same nested IF? Yes, each IF can return any value type. For example, =IF(A1>10,"High",A1*2) returns text “High” or a number. Just remember that text needs quotes.

How do I nest IF with AND or OR? You can put AND or OR inside the logical test: =IF(AND(A1>0,A1<100),"Valid","Invalid"). This is not nesting, but it tests multiple conditions at once. For more than two conditions, nested IFs or IFS are clearer.

Why does my nested IF return #VALUE!? Often this happens when a cell contains text and your formula tries to compare it with a number. For example, =IF(A1>10,"Yes","No") will return #VALUE! if A1 contains “abc”. Use the ISNUMBER function to handle text: =IF(ISNUMBER(A1),IF(A1>10,"Yes","No"),"Not a number").

What is the difference between nested IF and IFS? IFS is a single function that takes pairs of condition and value: =IFS(A1>90,"A",A1>80,"B",TRUE,"C"). Nested IF uses multiple IF functions. IFS is shorter and easier to read, but it does not allow different calculations in each branch; nested IF can.

Can I use nested IF in conditional formatting? Yes, you can use a formula like =IF(A1>100,TRUE,FALSE) in a conditional formatting rule, but you usually just write the condition directly: =A1>100. Nested IF is rarely needed there.

How do I debug a nested IF that returns the wrong result? Use the Evaluate Formula tool (Formulas tab > Formula Auditing > Evaluate Formula). It shows each step. Also, check the order of conditions—the first true condition wins. For example, if you test A1>80 before A1>90, a score of 95 will return “B” instead of “A”.

Related

Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.

More in Formulas & functions

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.