Excel function reference

IF

Quick answer

Tests a condition and returns one value when it's true, another when it's false.

IF(logical_test, value_if_true, [value_if_false])

IF is the function nearly every other conditional tool in Excel is built on top of: COUNTIF, SUMIF, and the whole IFS family all boil down to the same TRUE/FALSE test IF uses directly. One condition, one value if it's true, one value if it's false.

IFs nest inside each other for more than two outcomes, and that works fine for two or three levels. Past that, each added level means another closing parenthesis to count and another branch to trace by eye, and a lookup table (VLOOKUP, or a plain IFS) is usually the more maintainable choice for anyone who has to edit the formula six months later, including the person who wrote it.

Syntax

IF(logical_test, value_if_true, [value_if_false])
ArgumentDescription
logical_testRequired. Any comparison that evaluates to TRUE or FALSE, e.g. B2>=60.
value_if_trueRequired. What to return when the test is TRUE.
value_if_falseOptional. What to return when the test is FALSE. Omit it and Excel returns FALSE by default.

A real example: flagging low stock before it hits zero

A simple reorder flag that reads more like a sentence than a formula:

=IF(B2<5,"Reorder soon","OK")

Using a threshold like 5 instead of testing for exactly 0 catches the problem while there's still time to act on it, which is usually the more useful version of this kind of check.

Worked examples

Pass or fail
AB
1StudentScore
2Dana71
=IF(B2>=60,"Pass","Fail") → Pass
A numeric result
AB
1ProductUnits Left
2Cable0
=IF(B2>0,B2,"Out of stock") → Out of stock

Common mistakes

  • Forgetting quotes around text results. "Pass" needs them, a number like 60 doesn't.
  • Nesting IFs many levels deep instead of switching to a lookup table once you're past 2-3 outcomes.
  • Testing = instead of a range check where a threshold, not an exact match, is what's meant.

Related functions

Try it yourself

A free, graded practice exercise using this exact function: instant feedback, no signup required.

Practice IF →