Learn › n8n Foundations: From Zero to First Automation › Flow Control: IF Node and Switch

Flow Control: IF Node and Switch

Beginner 🕐 12 min Lesson 9 of 15
What you'll learn
  • Use the IF node to route items down true/false branches based on conditions
  • Use the Switch node to route items across three or more branches
  • Combine AND/OR logic in conditions and connect downstream nodes to each output

Why Branching Matters

A workflow that does the same thing to every item is useful. A workflow that decides what to do based on the data — that is where automation gets genuinely powerful. n8n's flow control nodes let you route items down different paths based on conditions, so you can handle multiple scenarios in a single workflow.

The IF Node: Two Paths

The IF node evaluates a condition and routes each item to one of two outputs: true (the condition matched) or false (it didn't). It is n8n's binary router.

To configure it: add an IF node, click "Add Condition", choose the data type (String, Number, Boolean, Date), select the operator (equals, contains, greater than, is empty, etc.), and set the value to compare against. You can combine multiple conditions with AND or OR logic.

Example: route emails by priority. Condition: {{ $json.subject }} contains "URGENT". Items matching the condition go out the True output to a Slack alert node; everything else goes out the False output to a regular Gmail folder node.

The Switch Node: Three or More Paths

When you have three or more branches, the Switch node is cleaner than chaining multiple IF nodes. It evaluates conditions in order and routes each item to the first matching output. You can define as many output branches as you need.

Switch has two modes:

  • Rules mode (default) — Define conditions visually. Each rule has a data type, operator, and value. The node checks rules top to bottom and routes to the first match. Unmatched items go to a "Fallback" output.
  • Expression mode — Write a JavaScript expression that returns the output index (0, 1, 2...). Use this for dynamic routing based on computed values.

Example: categorise support tickets by department. Rule 1: subject contains "billing" → Finance path. Rule 2: subject contains "technical" → Engineering path. Rule 3: subject contains "account" → Account Management path. Fallback → General queue.

Both Paths Continue the Workflow

Items that go out the True and False outputs of an IF node (or any output of a Switch node) continue through the nodes connected to that output. You connect different nodes to each output to define what happens in each case. The paths can rejoin later using a Merge node if you want to bring the results back together.

Practical Tips

When building conditional workflows, always add a test node or a "No Operation" node to the outputs during development so you can see what data is flowing down each path. In production, make sure you have connected all Switch outputs — items that fall through a missing output are silently dropped, which can cause data loss that is hard to debug.

Key takeaways
  • The IF node has two outputs — true and false; use it for binary routing decisions
  • The Switch node handles three or more branches — it checks rules top to bottom and routes items to the first matching output
  • Unmatched Switch items go to the Fallback output — always connect it or items will be silently dropped