An automation without logic is just a script. By mastering the core logic nodes, you transform simple data transfers into intelligent, decision-making systems.
1Conditional Branching: IF & Switch
The IF node is the binary gatekeeper of any workflow. It evaluates a condition — score > 80, country == 'US', status != 'closed' — and routes data to either a True or False output port. It's the if/else of your visual canvas.
When your logic gets more complex and you have more than two outcomes, the Switch node is your tool. Instead of nesting three IF nodes inside each other (which makes your canvas look like a bowl of spaghetti), a single Switch node creates multiple output routes from one decision point. Route leads by region, tickets by priority, or orders by fulfillment type — all with one node, all readable at a glance.
The practical rule: use IF for binary yes/no decisions, and Switch for any routing that has 3 or more possible paths.
// IF node logic (conceptual)
if (lead.score > 80) {
// Output: TRUE port
-> send to sales team
} else {
// Output: FALSE port
-> add to nurture sequence
}
// Switch node logic (conceptual)
switch (lead.region) {
case 'US': -> US Sales Team
case 'EU': -> EU Sales Team
case 'APAC': -> APAC Sales Team
default: -> General Queue
}2Data Management: Set & Merge
The Set node is deceptively powerful. It's n8n's way of saying 'from this point forward, the data looks like this'. You use it to define new fields, rename confusingly-named API fields to something readable, and most importantly, to prune — remove all the noise so only the fields your next node needs survive.
This habit of setting data early pays enormous dividends during debugging. When every node downstream sees a clean, predictable object instead of a 40-field API response, mapping variables is trivial and errors are immediately obvious.
The Merge node is the opposite — it brings things together. It combines data from parallel branches (enriching a contact with data from two different APIs simultaneously, for example) or acts as a synchronization gate that won't proceed until all incoming paths have delivered their data.
// Before Set node: raw API response
{
"user_id": 12345,
"created_at": "2024-01-01",
"first_name": "Alex",
"last_name": "Chen",
"metadata": { ... } // 30+ useless fields
}
// After Set node: clean output
{
"name": "Alex Chen",
"userId": 12345
}3Combining Logic in Real Workflows
The real power surfaces when you combine these four nodes into a coherent decision engine. A typical lead-routing workflow might: (1) Set the incoming webhook payload to a clean { name, email, score, region } object, (2) use a Switch to route by region, (3) within each regional branch, use an IF to check if the score exceeds the threshold for immediate sales outreach, and (4) Merge both the high-score and low-score paths back together into a single stream before logging the result to a Google Sheet.
This pattern — Set → Switch → IF → Merge — is not unique to this example. It appears in customer support triage, content publishing pipelines, financial approval flows, and almost every non-trivial automation you'll build.
Master these four nodes and you have the vocabulary to describe almost any business process in n8n.
// Full routing pipeline
[Webhook Trigger]
→ [Set: keep name, email, score, region]
→ [Switch: by region]
→ US Branch: [IF: score > 80]
True → [Slack: @sales-us]
False → [HubSpot: add to nurture]
→ EU Branch: [IF: score > 75]
True → [Slack: @sales-eu]
False → [HubSpot: EU nurture]
→ [Merge: all paths]
→ [Google Sheets: log result]4Step-by-Step Breakdown
Intelligence Hub. Workflows need intelligence to function efficiently. In this lesson, we will systematically master the 'Big Four' core logic nodes that form the brain of your workflow. These nodes are precisely what allow your automation to actively make decisions and route data properly.
Data Manager. The 'Set' node is your ultimate data manager. Use it directly to define new variables, explicitly rename existing ones, or carefully prune away useless metadata. This effectively ensures you only pass the exact fields you need for the rest of the workflow.
Binary Routing. The 'IF' node acts as a strict binary switch. It carefully checks a specific condition you configure and immediately routes the flowing data to either a dedicated 'True' path or a 'False' path for granular handling.
Checkpoint: You want to route leads differently based on three distinct regions (US, EU, Asia). Which node is most efficient?
- →Multiple nested IF nodes
- →A single Switch node
Multi-Path Routing. The 'Switch' node is explicitly designed for handling multi-path logic. Instead of chaining messy IFs, it effectively allows you to quickly create dozens of independent output rules based on a single, evaluated variable.
Data Synchronization. The 'Merge' node acts as the critical glue that holds streams together. It reliably combines data flowing from entirely different branches back into a single unified stream, or it waits patiently for two separate, concurrent tasks to fully finish.
Checkpoint: In an 'IF' node, what happens to data that does NOT meet the condition?
- →It is deleted automatically
- →It flows out of the 'False' output port
Applied Intelligence. By thoroughly mastering these exact core nodes, you can confidently build powerful workflows that actually 'think'. You will easily handle errors, dynamically route your high-value leads, and sync complex datasets seamlessly.
Optimization Strategy. Pro-tip: Always strategically use the 'Set' node very early in your workflow to isolate and keep only the specific data fields you actually need. This single habit undeniably makes debugging substantially faster.
Checkpoint: True or False: The Merge node can wait for multiple separate inputs to arrive before it triggers the next step.
- →True
- →False
Intelligent Status. Core logic successfully mastered! Your automation now officially possesses a decision-making brain and is ready for advanced tasks.
HTTP Node Next. Next, we will shift gears entirely and learn exactly how to master the single most versatile node in all of n8n: The HTTP Request Node.
Conclusion. With IF, Switch, Set, and Merge safely in your automation toolkit, absolutely no workflow logic is too complex for you to build and successfully scale.
Route a Real Conditional Branch. Finish routing to the true or false branch based on a condition function, like an If node.
Level Up 🚀
Advanced cheat sheets, SEO tricks, and interview prep for this topic.
Browser Support
Fully supported.
Fully supported.
Fully supported.
Fully supported.
Accessibility (A11y)
1Name Switch Node Outputs Descriptively, Not by Index Number
A Switch node with outputs labeled '0', '1', '2' forces anyone reading the workflow (including future maintainers using screen magnification or reader tools) to trace wires to understand routing — label each output port with its actual meaning (e.g. 'US Region', 'EU Region') so the workflow's logic is self-documenting.
Switch output: 'US Region' (not '0')SEO Implications
- 1
Target 'n8n IF vs Switch' as a Distinct Comparison Search
Builders new to n8n specifically search for when to use IF versus Switch, since both handle conditional routing — content that directly answers 'IF for binary, Switch for 3+ paths' captures that comparison-intent search better than describing each node in isolation.
Best Practices
Use the Set Node Early to Prune Noisy API Responses
Passing a 40-field raw API response through your entire workflow makes every downstream node harder to configure and debug. Use Set immediately after any external data pull to keep only the fields you actually need.
Prefer Switch Over Nested IF Nodes Once You Have 3+ Outcomes
Nesting IF nodes inside each other for multi-way branching quickly becomes an unreadable tangle on the canvas. A single Switch node with clearly labeled outputs keeps multi-way routing logic visible at a glance.
Frequent Bugs
Using a Merge node expecting it to wait for all incoming branches, but one branch never fires (e.g. an IF's False path with no downstream nodes), leaving the workflow hung waiting indefinitely.
Ensure every branch feeding into a Merge node's synchronization mode actually produces output on every run — add a fallback node on branches that might otherwise dead-end, or switch the Merge node's mode if waiting for all inputs isn't actually required.
Real-World Examples
Support Ticket Triage Pipeline
A support automation uses Set to normalize an incoming ticket into { subject, priority, category }, a Switch to route by category (Billing, Technical, General), and within each branch an IF checks priority to decide between immediate Slack alert versus queued email — all four node types working together in one coherent decision engine.
[Set: normalize ticket] → [Switch: by category] → [IF: priority == 'urgent'] → Slack or Queue