Branching: IF and Switch Logic
So far every workflow you built ran in a straight line. Real automations rarely do. A new lead might be high value or low value; an order might be paid or refunded; a message might be a question or spam. Each case deserves a different action. Branching is how a workflow makes that choice and sends items down different paths. n8n gives you two nodes for this: IF for a yes/no split, and Switch for many routes at once.
What You'll Learn
- How the IF node splits items into two paths, true and false
- How the Switch node routes items into three or more paths
- How conditions are evaluated per item, not per workflow
- A complete branching workflow you can import and run
- How to choose between IF and Switch
The IF node: a two-way fork
The IF node checks a condition for each item. Items where the condition is true leave through the true output; items where it is false leave through the false output. You then connect a different node to each output, and the two paths do different things.
Decision
Is the order amount 100 or more?
- If amount >= 100
True path
Send a VIP thank-you
- If amount < 100
False path
Send the standard receipt
The key thing to internalize: the condition is checked per item. If ten items flow into the IF node, each one is tested on its own, and the ten get sorted into the true and false outputs accordingly. Nothing about the workflow as a whole is being decided; each item finds its own path.
A typical IF condition compares a field to a value. In the editor you build it visually: choose the left value (often an expression like {{ $json.amount }}), choose an operator (is equal to, is greater than, contains, and so on), and set the value to compare against. Conditions can be combined with AND/OR when you need more than one test.
The Switch node: many routes
When you have more than two outcomes, chaining IF nodes gets messy. The Switch node is built for this: it evaluates a value and sends each item to one of several named outputs, plus an optional fallback for anything that matches nothing.
Decision
What is the ticket type?
- If type = 'bug'
Engineering path
Create a dev task
- If type = 'billing'
Finance path
Notify billing
- If type = 'question'
Support path
Auto-reply with docs
- If no match
Fallback path
Send to a human
Switch keeps one node responsible for all the routing, which is far easier to read and maintain than a tangle of IF nodes. A good rule: two outcomes, use IF; three or more, use Switch.
A branching workflow you can run
The workflow below has a manual trigger, a Code node that creates three sample orders with different amounts, and an IF node that splits them by amount. Copy it, paste it onto your canvas, and run it.
{
"name": "Branch by Amount",
"nodes": [
{
"parameters": {},
"id": "trig-1",
"name": "When clicking Test",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [220, 300]
},
{
"parameters": {
"jsCode": "return [\n { json: { customer: 'Ada', amount: 120 } },\n { json: { customer: 'Alan', amount: 40 } },\n { json: { customer: 'Grace', amount: 100 } }\n];"
},
"id": "seed-1",
"name": "Make Orders",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [440, 300]
},
{
"parameters": {
"conditions": {
"options": { "caseSensitive": true, "typeValidation": "strict" },
"combinator": "and",
"conditions": [
{
"id": "c1",
"leftValue": "={{ $json.amount }}",
"rightValue": 100,
"operator": { "type": "number", "operation": "gte" }
}
]
},
"options": {}
},
"id": "if-1",
"name": "Amount >= 100?",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [680, 300]
},
{
"parameters": {
"mode": "manual",
"assignments": {
"assignments": [
{ "id": "a1", "name": "tier", "value": "VIP", "type": "string" }
]
},
"options": {}
},
"id": "set-vip",
"name": "Tag VIP",
"type": "n8n-nodes-base.set",
"typeVersion": 3,
"position": [920, 200]
},
{
"parameters": {
"mode": "manual",
"assignments": {
"assignments": [
{ "id": "a2", "name": "tier", "value": "Standard", "type": "string" }
]
},
"options": {}
},
"id": "set-std",
"name": "Tag Standard",
"type": "n8n-nodes-base.set",
"typeVersion": 3,
"position": [920, 400]
}
],
"connections": {
"When clicking Test": {
"main": [[{ "node": "Make Orders", "type": "main", "index": 0 }]]
},
"Make Orders": {
"main": [[{ "node": "Amount >= 100?", "type": "main", "index": 0 }]]
},
"Amount >= 100?": {
"main": [
[{ "node": "Tag VIP", "type": "main", "index": 0 }],
[{ "node": "Tag Standard", "type": "main", "index": 0 }]
]
}
}
}
The IF node's condition is summarized as a config table so you can see it at a glance:
Node: Amount >= 100? (IF)
| Left value | Operator | Right value |
|---|---|---|
={{ $json.amount }} | is greater than or equal to | 100 |
Run it, then click each output of the IF node. The true output carries Ada (120) and Grace (100); the false output carries Alan (40). Follow the connections and you will see the Tag VIP node received two items and Tag Standard received one. The single condition sorted three items into two paths automatically.
Notice how the connections JSON encodes the fork: the IF node's main array has two sub-arrays. The first is the true output (to Tag VIP), the second is the false output (to Tag Standard). That ordering, true first then false, is how every IF branch is wired.
Challenge
- Change the threshold from
100to50and re-run. Now Ada, Grace, and Alan should all land on the true path. Confirm it. - Add a third sample order with
amount: 0and re-run. Which path does it take, and why? - Bigger stretch: replace the IF node with a Switch node that creates three tiers, for example
amount >= 100is "Gold,"amount >= 50is "Silver," and everything else is "Bronze." Wire a Set node to each output.
Choosing between IF and Switch
When to reach for each branching node
| Criteria | IF node | Switch node |
|---|---|---|
| Number of paths | Exactly two (true/false) | Three or more |
| Best for | Yes/no decisions | Routing by category |
| Fallback path | The false output | A dedicated fallback output |
| Readability at scale | Gets messy when chained | Stays clear with many cases |
IF node
- Number of paths
- Exactly two (true/false)
- Best for
- Yes/no decisions
- Fallback path
- The false output
- Readability at scale
- Gets messy when chained
Switch node
- Number of paths
- Three or more
- Best for
- Routing by category
- Fallback path
- A dedicated fallback output
- Readability at scale
- Stays clear with many cases
Key Takeaways
- Branching sends items down different paths so each case gets the right action.
- The IF node is a two-way fork: items leave through the true or false output based on a per-item condition.
- The Switch node routes items into three or more named paths, plus an optional fallback, and stays readable as cases grow.
- Conditions are evaluated per item, so one node sorts a whole list of items across its outputs automatically.
- In workflow JSON, an IF node's two outputs are encoded as the first (true) and second (false) sub-arrays of its connections.

