In Excel, the IF function checks whether a condition is true and returns one result if it is, or another if it is false. For example, with a student’s score in A2, =IF(A2>=70,"Pass","Fail") displays Pass for a score of 70 or higher and Fail otherwise.
IF is useful for turning a rule into a repeatable calculation: classify scores, flag overdue dates, calculate a conditional discount, or label missing information. The examples below use Microsoft Excel for Microsoft 365 on Windows and explain what each formula expects, what it returns, and when a different approach may be clearer.
How the IF Function Works
Excel evaluates a logical test, such as whether a number is greater than or equal to a threshold, and then chooses between two outcomes. The outcomes can be text, numbers, calculations, cell references, or even another IF function. The result appears in the cell containing the formula; the formula itself remains available in the formula bar.
IF does not change the original values it checks. If a formula classifies the score in A2 as Pass, the score remains in A2. This distinction matters when you sort, filter, chart, or reuse the original data: the formula creates a result alongside the source value rather than replacing it.
In Microsoft 365 for Windows, enter a formula in a cell and press Enter. To use it for additional rows, select the cell and drag the fill handle—the small square at its lower-right corner—down. Excel normally adjusts relative references as the formula is copied, so a reference to A2 becomes A3 on the next row. On Mac, the function and formula behavior are the same; ribbon layout and some keyboard shortcuts differ. Excel for the web also supports IF, though its interface is browser-based.
Syntax and the Three Parts of an IF Formula
The function’s structure is IF(logical_test, value_if_true, [value_if_false]). The square brackets in this syntax indicate that the last argument is optional; do not type the brackets into a formula. Excel formulas begin with an equals sign, and this article uses commas between arguments.
- logical_test: The condition Excel evaluates. Comparisons commonly use =, >, <, >=, <=, or <> (not equal to).
- value_if_true: What Excel returns when the condition is true. Put text in straight double quotation marks, or provide a number, calculation, or reference.
- value_if_false: What Excel returns when the condition is false. Although optional, including it often makes the outcome easier to understand.
For example, suppose A2 contains a test score. With the score in A2, =IF(A2>=70,"Pass","Fail") returns Pass when A2 is 70 or more and Fail when it is below 70. The comparison includes exactly 70 because the operator is greater than or equal to. Changing the operator to > would make a score of 70 fail the test.
Practical IF Examples for Common Tasks
For a sales incentive, imagine that B2 contains a salesperson’s sales total and the rule is a 5% commission for sales of at least $10,000, with no commission below that threshold. With the sales amount in B2, =IF(B2>=10000,B2*5%,0) returns 600 when B2 is 12,000, because 12,000 multiplied by 5% is 600. If B2 is 8,000, the result is 0. This is an illustrative spreadsheet calculation, not advice about setting a real compensation plan.
IF can also show whether required information has been entered. With a name expected in A2, =IF(A2="","Missing","Entered") displays Missing if A2 is empty and Entered otherwise. This is handy in a checklist or intake sheet. Be aware that a formula that returns an empty text string can also look blank; if the distinction between a truly empty cell and a formula-generated blank matters, test the data source more carefully.
Another common task is comparing a date with a cutoff. Suppose A2 contains a valid Excel date and the rule is to label dates on or after January 1, 2026 as part of the current period. With the date in A2, =IF(A2>=DATE(2026,1,1),"Current period","Earlier period") returns Current period for January 1, 2026 or a later date, and Earlier period for an earlier date. DATE constructs a date from year, month, and day, avoiding ambiguity between regional date formats. Confirm that the source cell contains a real Excel date rather than text that merely looks like one.
Combining IF with AND and OR
Use AND when every condition must be true, and OR when at least one condition is enough. These functions are often clearer than writing several separate IF formulas. For example, a fictional eligibility rule might require a score of at least 70 and a completed status marked Yes. If B2 contains the score and C2 contains Yes or No, with these values in their stated cells, =IF(AND(B2>=70,C2="Yes"),"Eligible","Not eligible") returns Eligible only when both conditions are met.
For a simple category check, suppose A2 contains a color and the label should be Special when the color is Red or Blue. With the color in A2, =IF(OR(A2="Red",A2="Blue"),"Special","Standard") returns Special for either listed color and Standard for other entries. Text comparisons in ordinary Excel formulas are generally not case-sensitive, so red also matches Red. If capitalization is important to the rule, use a case-sensitive approach rather than assuming IF distinguishes it.
When a rule combines conditions, write out the rule in plain language first. “Score is at least 70 and status is Yes” signals AND; “color is Red or Blue” signals OR. This simple translation helps prevent a formula that looks plausible but applies the wrong logic. It is also worth testing a case where all conditions are true, one where none are true, and one where only some are true.
Using Nested IF for Several Outcomes
A nested IF places one IF inside another so Excel can return among more than two outcomes. For score bands, suppose A2 contains a score: 90 or higher earns A, 80–89 earns B, 70–79 earns C, and anything lower earns F. With the score in A2, =IF(A2>=90,"A",IF(A2>=80,"B",IF(A2>=70,"C","F"))) returns B for a score of 84. Excel checks the thresholds from left to right and stops at the first true test.
The order matters. The highest threshold comes first in this example because a score of 95 also satisfies the lower thresholds. If the formula checked 70 first, that score would receive C and never reach the A test. Write ranges in descending or ascending order deliberately, and verify the boundary values: 69, 70, 79, 80, 89, and 90 in this grading scheme.
Nested IF is workable for a few outcomes, but it becomes harder to read and maintain as categories grow. For a long list of score bands or lookup rules, a reference table with a lookup function may be easier to update. In Excel for Microsoft 365 or Excel 2021, functions such as XLOOKUP can be an option, but the table must be organized to match the chosen lookup method. A compact formula is not automatically a better formula if another person cannot readily check the rules.
Choosing IF, IFS, or a Different Tool
Use IF for one yes-or-no decision, or a small number of clearly ordered branches. Excel also provides IFS for testing several conditions without nesting each new IF inside the previous one. With the score in A2, =IFS(A2>=90,"A",A2>=80,"B",A2>=70,"C",A2<70,"F") returns B for 84. IFS is available in Microsoft 365 and Excel 2019 or later. It returns the result for the first true condition, so condition order still matters; include a final condition that covers the remaining cases to avoid an error when none are true.
IF is not the same as conditional formatting. A formula can create a value such as Late or Pass in a cell, which can then be used in other calculations. Conditional formatting changes how cells look based on rules but does not replace their stored values. In Excel for Microsoft 365 on Windows, start a visual rule from Home > Conditional Formatting. On Mac the feature is also under Home, though the ribbon presentation can vary. Choose IF when the workbook needs a calculated result, and conditional formatting when the goal is visual emphasis.
For finding a matching item in a table, a lookup function may be more appropriate than a long series of IF checks. For example, a product category or tax rate maintained in a separate table is usually easier to update in that table than to edit inside a deeply nested formula. Choose based on where the rule belongs: a simple decision can live in IF; a maintained list of mappings often belongs in a table.
Common IF Problems and How to Fix Them
- Unexpected FALSE: If the third argument is omitted, Excel returns FALSE when the test is false. Add an explicit outcome, such as 0 or a text label, if that is more useful.
- Text without quotation marks: Literal text outcomes need straight double quotation marks. Without them Excel may interpret a word as a named range and return an error.
- Wrong comparison boundary: Check whether the rule means greater than or greater than or equal to. This one-character difference changes what happens exactly at the cutoff.
- Numbers stored as text: A cell that looks like 100 may contain text rather than a numeric value. Comparisons and arithmetic can then behave unexpectedly. Check the source data and convert it to numbers where appropriate.
- Dates stored as text: A date-looking string may not be a date value. Use a recognized date entry or convert the source data, then check the cell’s underlying value and formatting.
- Unbalanced parentheses: Nested formulas need a closing parenthesis for each opening one. Excel often helps identify an incomplete formula, but reviewing the nesting from the inside out is useful.
When a formula gives an unexpected result, test the logical condition separately in an empty cell or inspect the input cells. Check one true case and one false case, including values at the threshold. Also consider blanks, spelling variations, extra spaces, and inconsistent data types. Excel’s formula result reflects the actual stored value, which may differ from how a cell appears because of formatting.
Frequently Asked Questions
What does IF do in Excel?
IF evaluates a condition and returns one specified result if it is true and another if it is false. It is commonly used to classify data or apply a rule to each row.
How do I write an IF formula with text?
Put literal text outcomes inside straight double quotation marks. For example, with a status in A2, =IF(A2="Done","Complete","In progress") returns Complete when A2 contains Done and In progress otherwise.
Can an IF formula return a blank?
Yes. To return an empty text string when a condition is false, use quotation marks with nothing between them as the false result. The cell can look blank even though it contains a formula, which is different from a genuinely empty cell.
How many IF functions can I nest?
Excel supports up to 64 nested IF levels, but that is a technical limit rather than a recommendation. Long formulas are difficult to audit; consider IFS or a lookup table when a rule has many possible outcomes.
Why does my IF formula show FALSE?
Usually the formula has no value_if_false argument, so Excel uses FALSE when the test is not met. Add a third argument for the result you want in that situation, such as a label, zero, or an empty text string.
A Reliable Way to Build and Check an IF Formula
Start by writing the decision in ordinary language, including what should happen in both cases. Identify the input cell, choose the comparison operator carefully, and decide whether the outcome should be text or a value that can be calculated later. Then test the formula with representative inputs, especially values exactly on a cutoff and missing or unusual data.
Finally, copy the formula through the intended rows and inspect a few results against the source data. If the rules change often, document the thresholds or keep them in a separate table rather than burying them in a complicated formula. A well-designed IF formula is not merely one that calculates; its conditions and outcomes should also be clear enough for someone else to verify.
Related
- Merge Day, Month, and Year in Excel
- Convert Text to Numbers in Excel in Bulk
- How to Mass Copy and Paste in Excel: Safe, Fast Steps
Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.
More in Formulas & functions
- Excel XLOOKUP Between Two Worksheets: ExamplesIf your lookup value is on one worksheet and the data to search is on another, XLOOKUP can…
- Excel PV Formula for Different PaymentsExcel’s PV function is designed for a fixed payment repeated over a set number of periods, so it…
- Excel Formula for Hours Between Two TimesTo calculate hours between two times in Excel, subtract the start time from the end time and multiply…
- How to Find Duplicate Entries in Excel with FormulasTo find duplicate entries in Excel, select the cells you want to check and choose Home > Conditional…
- Sort Excel Column Without a Header Safely in ExcelTo sort an Excel column that has no header, select the data cells, then choose Data > Sort…
- Excel EDATE With Days Instead of Months: What to UseNo. EDATE adds months, not days; if A2 contains 10-Feb-2024 and B2 contains 30, use =A2+B2 to get…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.