n8n IF & Switch Node: Conditional Branching Logic Guide


⚡ n8n Workflow Automation
T3 · Branching Logic

n8n IF & Switch Node: Conditional Branching Logic Guide

Conditional branching splits a workflow into separate paths based on
data‑driven rules. n8n provides two core nodes for this: the IF node
for binary true/false decisions, and the Switch node for multi‑way
routing based on exact values or ranges. Both evaluate conditions
using expressions, transforming linear automations into intelligent,
adaptive processes.

Node Decision Type Output Branches Operator Examples
IF Binary 2 (true, false) equals, greater than, contains, isEmpty, regex
Switch Multi‑way 3+ (one per condition) exact value match, numeric range, expression evaluation

How does the n8n IF node create a true/false branching path?

The IF node evaluates a single condition against each incoming data
item and routes it to the true branch if the
condition matches, otherwise to the false branch.
Conditions compare two operands: a value (from a field or expression)
and a reference value, using operators like equals, contains, or
greater than.
[1]

Each branch can connect to any number of subsequent nodes, allowing
different processing for matched and unmatched items. For example,
check if an invoice total exceeds $1,000, then route high‑value
invoices to a manager approval flow and low‑value ones directly to
payment processing. This node is also the foundation for
error handling and conditional logic in automation.

What conditions and expression operators can you use in an n8n IF node?

An IF node supports 10 comparison operators:
equals, not equals, greater than, less than, greater than or equal
to, less than or equal to, contains, not contains, is empty, and
is not empty. The left operand pulls from a field, an expression
like {{ $json.price }}, or a static value.
[1]

Advanced usage combines expressions and functions. For instance,
{{ $json.tags.includes("urgent") ? 'high' : 'normal' }}
pre‑processes a field before the IF condition evaluates it.
Combine multiple conditions by chaining IF nodes in series—each node
further refines the true branch. Learn more about expression syntax
in our
nodes & expressions guide.

How does the Switch node route data to three or more branches?

The Switch node evaluates multiple conditions simultaneously and
sends each data item to exactly one matching output branch. You
define routing rules based on a single field or expression, with
each rule specifying a comparison type: value match, numeric range,
or regex. The node auto‑creates a branch for each rule you add.
[2]

Unlike the IF node, which offers only two paths, the Switch node
can have 3 or more output branches—ideal for
routing support tickets by category, leads by country, or orders
by status. When no rule matches an item, the node sends it to a
fallback “No Match” output branch, preventing data loss.
Sub‑workflows also benefit from Switch routing
for modular task distribution.

How do you build multi‑condition routing with chained IF and Switch nodes?

Multi‑condition routing combines multiple IF nodes in sequence or a
Switch node with IF nodes on its branches. An IF node’s true branch
can link to a second IF node, creating nested logic equivalent to
“AND” conditions. A Switch node can have an IF node on each output
branch for further refinement.
[3]

For complex “AND” and “OR” logic within a single node, use
expressions. {{ $json.country === 'US' && $json.amount > 500 }}
in a Switch rule combines two conditions. When rule count exceeds
5–7, maintain readability by separating logic into a sub‑workflow.
See our
use cases guide
for real‑world multi‑condition implementations.

⚠️ Performance Note: The Switch node checks each
rule sequentially. Arrange the most frequent matches first to
minimize average evaluation time. For more than 20 rules, consider
using a Code node with a lookup table to reduce node overhead.
[2]

When should you choose an IF node over a Switch node?

Choose an IF node when the decision is strictly binary—true or
false—such as checking if a field is empty, comparing a single
threshold, or validating user permissions. An IF node is simpler
to configure and read, with exactly two output connectors that
make the workflow logic immediately clear.
[3]

Switch to the Switch node when you have three or more
distinct outcomes, such as routing by lead source (web, chat, email)
or order status (pending, shipped, returned). Also use it when the
routing depends on multiple possible values of the same field, as
this avoids stacking multiple IF nodes in a chain. For a deep dive
into node architecture, visit our
architecture & scaling guide.

How do n8n expressions power dynamic conditions in IF and Switch nodes?

Expressions inside an IF or Switch condition dynamically compute the
comparison value at runtime. Wrapped in {{ }}, they
can call built‑in functions like $now,
$if, $json, or user‑defined code
references. This transforms static conditions into context‑aware,
data‑driven decisions that adapt to each incoming item.
[4]

Use Case Expression Example Node
Combine fields {{ $json.firstName + ' ' + $json.lastName }} IF / Switch
Dynamic threshold {{ $json.total > $vars.approvalLimit }} IF
Date comparison {{ $now.minus({days: 7}) > $json.createdAt }} IF
Category mapping {{ $json.tags.includes('vip') ? 'priority' : 'standard' }} Switch

Expressions unlock advanced branching strategies: concatenate
fields for unique keys, compute on‑the‑fly thresholds, or run
ternary operators for inline categorization. For a complete
reference of all expression functions, see our
node expressions and techniques guide.

References

This guide is for informational purposes only. For the most current and authoritative information,
always refer to the official n8n website (n8n.io) and
the n8n documentation. Product details and features
may change over time.



Leave a Reply

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