Skip to main content
RapidDev - Software Development Agency
n8n-tutorial

How to Use the IF Node in n8n for Conditional Branching

The IF node in n8n creates conditional branches in your workflow. Configure conditions using string, number, boolean, or regex operators in the conditions panel. Items matching the condition flow through the True output, while non-matching items go to the False output, letting you build dynamic decision logic.

What you'll learn

  • How to add and configure the IF node in a workflow
  • How to set up conditions with string, number, boolean, and regex operators
  • How to chain multiple conditions with AND/OR logic
  • How to connect True and False outputs to different workflow branches
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Beginner8 min read10-15 minutesn8n 1.0+, all installation methodsMarch 2026RapidDev Engineering Team
TL;DR

The IF node in n8n creates conditional branches in your workflow. Configure conditions using string, number, boolean, or regex operators in the conditions panel. Items matching the condition flow through the True output, while non-matching items go to the False output, letting you build dynamic decision logic.

How to Use the IF Node in n8n

The IF node is one of the most essential nodes in n8n. It evaluates conditions against your workflow data and routes items to different branches based on the result. This allows you to build workflows that respond differently to different inputs, such as sending a notification only when a value exceeds a threshold or handling successful and failed API responses differently.

Prerequisites

  • A running n8n instance with access to the workflow editor
  • Basic understanding of n8n workflow concepts such as nodes and connections
  • At least one trigger node set up to provide input data

Step-by-step guide

1

Add an IF node to your workflow

Click the plus button on any node output to add a new node, then search for IF in the node panel. Click the IF node to add it to your canvas. It appears with two outputs labeled True and False. Connect the IF node after the node whose output data you want to evaluate. The IF node processes each item individually, routing each one to the True or False output based on the condition.

Expected result: An IF node appears on your canvas connected to the previous node, with two output branches ready to be configured.

2

Configure a basic condition

Click on the IF node to open its settings panel. In the Conditions section, click Add Condition and choose the data type: String, Number, Boolean, or Date Time. For each condition, set three values: the left value (usually an expression referencing input data), the operator (such as equals, contains, greater than), and the right value (the comparison target). Use expressions like {{ $json.status }} to reference fields from the incoming data.

typescript
1// Example conditions:
2
3// String: Check if status equals "active"
4// Left value: {{ $json.status }}
5// Operator: equals
6// Right value: active
7
8// Number: Check if amount is greater than 100
9// Left value: {{ $json.amount }}
10// Operator: greater than
11// Right value: 100
12
13// Boolean: Check if isVerified is true
14// Left value: {{ $json.isVerified }}
15// Operator: equals
16// Right value: true

Expected result: The condition is configured and shows the field reference, operator, and comparison value in the conditions panel.

3

Add multiple conditions with AND/OR logic

Click Add Condition again to add more conditions. By default, multiple conditions use AND logic, meaning all conditions must be true for the item to go to the True output. To switch to OR logic, click the AND dropdown at the top of the conditions section and select OR. With OR logic, the item goes to the True output if any single condition is met.

typescript
1// AND example: User must be active AND have a premium plan
2// Condition 1: {{ $json.status }} equals "active"
3// Condition 2: {{ $json.plan }} equals "premium"
4// Logic: AND — both must be true
5
6// OR example: Send alert if temperature is too high OR too low
7// Condition 1: {{ $json.temperature }} greater than 100
8// Condition 2: {{ $json.temperature }} less than 0
9// Logic: OR — either triggers the True branch

Expected result: Multiple conditions appear in the panel with the selected AND or OR logic operator displayed between them.

4

Use regex conditions for pattern matching

For complex text matching, select the String data type and use the regex operator. This lets you test input values against regular expression patterns. The regex condition is useful for validating email formats, extracting patterns from text, or matching partial strings with specific formats. Enter the regex pattern in the right value field without surrounding slashes.

typescript
1// Regex: Check if email is a Gmail address
2// Left value: {{ $json.email }}
3// Operator: regex
4// Right value: @gmail\.com$
5
6// Regex: Check if phone number matches a pattern
7// Left value: {{ $json.phone }}
8// Operator: regex
9// Right value: ^\+1[0-9]{10}$

Expected result: Items with values matching the regex pattern route to the True output. Non-matching items route to the False output.

5

Connect downstream nodes to True and False outputs

Drag a connection from the True output (top connector) to the node you want to run when the condition passes. Drag another connection from the False output (bottom connector) to a different node for the fallback path. You can connect multiple nodes to each output, and you do not need to connect both outputs if you only need one path. Items that do not match simply stop if the False output is unconnected.

Expected result: Your workflow has two distinct branches after the IF node. Test execution shows items flowing to the correct branch based on the condition.

Complete working example

if-node-workflow.json
1{
2 "name": "IF Node Example — Order Processing",
3 "nodes": [
4 {
5 "parameters": {},
6 "name": "Manual Trigger",
7 "type": "n8n-nodes-base.manualTrigger",
8 "typeVersion": 1,
9 "position": [250, 300]
10 },
11 {
12 "parameters": {
13 "jsCode": "return [\n { json: { customer: 'Alice', amount: 250, status: 'paid' } },\n { json: { customer: 'Bob', amount: 50, status: 'pending' } },\n { json: { customer: 'Carol', amount: 150, status: 'paid' } },\n { json: { customer: 'Dave', amount: 30, status: 'failed' } }\n];"
14 },
15 "name": "Sample Orders",
16 "type": "n8n-nodes-base.code",
17 "typeVersion": 2,
18 "position": [450, 300]
19 },
20 {
21 "parameters": {
22 "conditions": {
23 "options": { "combineOperation": "all" },
24 "conditions": [
25 {
26 "leftValue": "={{ $json.status }}",
27 "rightValue": "paid",
28 "operator": { "type": "string", "operation": "equals" }
29 },
30 {
31 "leftValue": "={{ $json.amount }}",
32 "rightValue": 100,
33 "operator": { "type": "number", "operation": "gt" }
34 }
35 ]
36 }
37 },
38 "name": "IF Paid and High Value",
39 "type": "n8n-nodes-base.if",
40 "typeVersion": 2,
41 "position": [650, 300]
42 },
43 {
44 "parameters": {
45 "jsCode": "// High-value paid orders — send to premium fulfillment\nconst items = $input.all();\nreturn items.map(item => ({\n json: {\n ...item.json,\n fulfillment: 'premium',\n processedAt: new Date().toISOString()\n }\n}));"
46 },
47 "name": "Premium Fulfillment",
48 "type": "n8n-nodes-base.code",
49 "typeVersion": 2,
50 "position": [850, 200]
51 },
52 {
53 "parameters": {
54 "jsCode": "// Standard or unpaid orders — send to review queue\nconst items = $input.all();\nreturn items.map(item => ({\n json: {\n ...item.json,\n fulfillment: 'standard-review',\n processedAt: new Date().toISOString()\n }\n}));"
55 },
56 "name": "Standard Review",
57 "type": "n8n-nodes-base.code",
58 "typeVersion": 2,
59 "position": [850, 400]
60 }
61 ],
62 "connections": {
63 "Manual Trigger": { "main": [[{ "node": "Sample Orders", "type": "main", "index": 0 }]] },
64 "Sample Orders": { "main": [[{ "node": "IF Paid and High Value", "type": "main", "index": 0 }]] },
65 "IF Paid and High Value": {
66 "main": [
67 [{ "node": "Premium Fulfillment", "type": "main", "index": 0 }],
68 [{ "node": "Standard Review", "type": "main", "index": 0 }]
69 ]
70 }
71 }
72}

Common mistakes when using the IF Node in n8n for Conditional Branching

Why it's a problem: Forgetting to switch the value field to expression mode when referencing input data

How to avoid: Click the expression editor icon next to the value field. If you type {{ $json.field }} in fixed mode, it is treated as a literal string, not an expression.

Why it's a problem: Comparing a number field using string operators

How to avoid: Select the correct data type for your condition. If you are comparing numeric values, choose Number as the condition type, not String. String comparison of numbers gives incorrect results, for example '9' is greater than '10' in string order.

Why it's a problem: Using AND logic when OR logic is needed, causing no items to match

How to avoid: Click the logic operator dropdown between conditions and switch from AND to OR. AND requires all conditions to be true, OR requires only one.

Why it's a problem: Leaving the False output unconnected without realizing items are silently dropped

How to avoid: If you need all items to continue regardless of the condition, connect both True and False outputs to the same downstream node or add a No Operation node to the False branch for clarity.

Best practices

  • Use descriptive names for your IF nodes such as 'IF Order Paid' instead of the default 'IF' to make workflows readable
  • Prefer strict equality operators over contains when matching exact values to avoid false positives
  • Always test both the True and False branches with sample data before activating a workflow
  • Use regex conditions sparingly — simple string operators are faster and easier to maintain
  • Combine the IF node with the Merge node when you need to rejoin split branches later in the workflow
  • Consider using the Switch node instead of chaining multiple IF nodes when you have three or more possible outcomes

Still stuck?

Copy one of these prompts to get a personalized, step-by-step explanation.

ChatGPT Prompt

I need to create a conditional branch in my n8n workflow. I want to check if {{ $json.status }} equals 'completed' AND {{ $json.amount }} is greater than 500. How do I configure the IF node for this?

n8n Prompt

Add an IF node after the HTTP Request node that checks if the response status code is 200 and the body contains a 'success' field set to true. Route failures to an error notification branch.

Frequently asked questions

What is the difference between the IF node and the Switch node in n8n?

The IF node has two outputs, True and False, for binary decisions. The Switch node supports multiple outputs for routing items to different branches based on multiple possible values. Use Switch when you have three or more outcomes.

Can the IF node evaluate expressions with calculations?

Yes. You can use any valid n8n expression in the condition values, including calculations. For example, set the left value to {{ $json.price * $json.quantity }} and compare it against a threshold number.

How does the IF node handle items with missing fields?

If a referenced field does not exist, the expression returns undefined. This typically causes the condition to evaluate as false, sending the item to the False output. Use the exists or does not exist operators to explicitly check for missing fields.

Can I have more than two branches from an IF node?

No, the IF node only has True and False outputs. For more branches, either chain multiple IF nodes or use the Switch node, which supports as many output branches as you need.

Does the IF node process all items or just the first one?

The IF node processes every item individually. Each item is evaluated against the conditions and routed to the appropriate output independently. If five items come in, each one is checked and sent to True or False based on its own data.

Can I combine AND and OR logic in a single IF node?

The IF node supports either AND or OR for all conditions, not a mix. For complex logic combining AND and OR, use nested IF nodes or a Code node that returns items to different outputs based on your custom logic.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Need help with your project?

Our experts have built 600+ apps and can accelerate your development. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.