Formulas

Excel IF Formula Explained: 6 Examples You Can Copy

The IF formula is how Excel makes decisions. It checks whether something is true, and then returns one result if it is and a different result if it is not. Pass or fail, discount or full price, eligible or not eligible — one short formula handles all of them. It is usually the first “real” formula people learn, and it stays useful in almost every spreadsheet you will ever build.

This guide takes about 15 minutes. You need only Excel — any version from the last two decades works, because IF is one of Excel’s oldest functions. All six examples are in copy boxes you can paste straight into your own sheet, and a practice file at the end lets you try them on real data.

Balance scale over a results table, illustrating an Excel IF formula comparing two outcomes

What the IF function does

Think of IF as a fork in the road. You give Excel a test — for example, “are the marks in B2 at least 50?” — and two possible answers. If the test is true, Excel returns the first answer; if it is false, Excel returns the second one. The cell then shows whichever answer applies, and it updates itself whenever the data changes.

That automatic updating is the real power. Change a mark from 45 to 55 and “Fail” becomes “Pass” without you touching the formula. The same idea powers price discounts, grade calculations, stock warnings and eligibility checks. Once you can write one IF, you can automate hundreds of small decisions in a sheet.

The IF syntax

=IF(logical_test, value_if_true, [value_if_false])

  • logical_test — the condition to check, such as B2>=50 or A2=”Paid”. It must end up TRUE or FALSE.
  • value_if_true — what to return when the test is true. It can be text in quotes, a number, or another calculation.
  • [value_if_false] — optional: what to return when the test is false. If you leave it out, Excel shows FALSE.

Only the first two arguments are required, but you will almost always use all three. The comparison signs you will use most are = (equal), > (greater than), < (less than), >= (at least), <= (at most) and <> (not equal). Text answers always go inside double quotes, like “Pass”.

Copy these formulas

Each box below works with the class data in the worked example further down (names in column A, marks in B, attendance in C, sales in D). Copy a box, paste it into your own sheet, and change the cell references to match your data.

Basic IF — pass or fail from marks in B2:

=IF(B2>=50,"Pass","Fail")

IF with a calculation — 10% discount when sales in D2 reach 1000, otherwise no discount:

=IF(D2>=1000,D2*0.1,0)

Nested IF — letter grades from marks (90+ = A, 80+ = B, 70+ = C, otherwise F):

=IF(B2>=90,"A",IF(B2>=80,"B",IF(B2>=70,"C","F")))

IF with AND — eligible only when marks are at least 50 AND attendance is at least 75:

=IF(AND(B2>=50,C2>=75),"Eligible","Not eligible")

IF with OR — flag a student who needs support when marks are under 40 OR attendance is under 60:

=IF(OR(B2<40,C2<60),"Needs support","OK")

IFS — the same grades as the nested IF, written flat (Excel 2019 or Microsoft 365):

=IFS(B2>=90,"A",B2>=80,"B",B2>=70,"C",TRUE,"F")

A worked example

Here is the small class table used in every example above — names in A, marks in B, attendance percentage in C, and sales figures in D:

Name (A)Marks (B)Attendance (C)Sales (D)
Ali85901200
Sara7268800
Ahmed45801500
Fatima91952000
Bilal3855600
Ayesha64771100

Put the basic IF in E2 — =IF(B2>=50,”Pass”,”Fail”) — and fill it down the column. Ali gets “Pass” because 85 is at least 50, Ahmed gets “Fail” because 45 is not, and Fatima gets “Pass” with 91. Reading the formula aloud: “If B2 is at least 50, show Pass, otherwise show Fail.”

The other boxes read the same way. The discount formula gives Ali 120 (10% of 1200) and Sara 0, because her 800 does not reach 1000. The AND formula marks Sara “Not eligible” — her marks pass, but her attendance of 68 is below 75, and AND needs both tests to be true. The OR formula flags only Bilal as “Needs support”, because he is the only student under 40 marks or under 60 attendance.

Nested IF or IFS — which to use

A nested IF puts one IF inside another, which is how the grade example checks 90, then 80, then 70 in order. It works in every Excel version, but the brackets pile up quickly and one misplaced bracket breaks the whole formula. Three levels, like the grades here, is about the comfortable limit for most people.

IFS does the same job without nesting: you list test–result pairs in order, and Excel returns the first one that is true. The final TRUE,”F” pair acts as the “everything else” case, exactly like the last value_if_false in a nested IF. IFS needs Excel 2019 or Microsoft 365 (it also works in Google Sheets), so use nested IF when you share files with people on older versions. For everything else, IFS is easier to read, check and extend.

Try it yourself: download the practice file

The practice file has the same class table from the worked example, six tasks matching the six copy boxes, and an answers sheet. Download it here: Excel IF practice file (with answers). Write each formula in the Practice sheet, fill it down the column, then check your answers — and tip: Ctrl + D fills a formula down, see our Excel Shortcuts guide. If a result does not change when you change a mark, the formula is probably pointing at the wrong cell.

Common mistakes

  • Forgetting the quotes around text. =IF(B2>=50,Pass,Fail) gives a #NAME? error — text answers must be “Pass” and “Fail” in double quotes.
  • Using = instead of >=. =IF(B2=50,…) only matches exactly 50. For “50 or more” you need >=.
  • Testing text that looks like a number. If marks were pasted as text, B2>=50 can behave strangely. Retype the number or convert the column to numbers first.
  • Nesting too deep. Beyond three or four levels, switch to IFS or a lookup table — our XLOOKUP guide covers the lookup approach for grade bands.
  • Semicolons instead of commas. Some regional Excel settings use ; between arguments. If a copied formula errors, that is the first thing to check.

Errors you might see

  • FALSE — the test was false and you left out value_if_false. Add the third argument to show what you actually want.
  • #NAME? — a text answer is missing its quotes, or you used IFS on an Excel version older than 2019. Check the quotes first, then the version.
  • #VALUE! — the test compares things that cannot be compared, often a number cell that secretly contains text. Check the cells your test points at.

IF also pairs well with other functions. Wrap a lookup in IFERROR to hide errors, or use it inside SUMIF and VLOOKUP formulas when a result should only appear under certain conditions.

Frequently asked questions

What does the IF formula do in Excel?

It tests a condition and returns one value if the condition is true and another if it is false. For example, =IF(B2>=50,”Pass”,”Fail”) shows “Pass” when B2 is at least 50 and “Fail” otherwise, and it updates automatically when B2 changes.

How many conditions can one IF formula check?

One test per IF, but you can combine tests with AND and OR inside the same formula, or nest IFs inside each other for several outcomes. For many outcomes, IFS (Excel 2019 and Microsoft 365) is cleaner than deep nesting.

Why does my IF formula show FALSE?

Because the test was false and you did not provide a value_if_false. Add the third argument — =IF(B2>=50,”Pass”,”Fail”) instead of =IF(B2>=50,”Pass”) — and Excel will show your chosen text instead of FALSE.

Can IF return a calculation instead of text?

Yes. The true and false results can be numbers or calculations, like =IF(D2>=1000,D2*0.1,0) for a 10% discount. Only text results need double quotes; numbers and formulas do not.

Does the IF formula work in Google Sheets?

Yes — IF, AND, OR and IFS all work in Google Sheets with the same syntax, so every formula in this guide can be pasted into a sheet there unchanged. Our Google Sheets formulas guide covers more functions that behave the same way.

Quick recap

=IF(test, answer if true, answer if false). Use AND when every condition must hold, OR when any one is enough, nested IF for a few outcomes in old Excel versions, and IFS for many outcomes in current ones. Master this one formula and most everyday spreadsheet decisions become automatic.

Leave a Reply

Your email address will not be published. Required fields are marked *