← Back to all articles

How to Create Multi-Step Workflows in n8n (Branching, Loops & Sub-Workflows)

A two-node workflow is a script with a UI. A multi-step workflow is a system: it branches on conditions, loops over data, delegates to sub-workflows, and survives failures. Here’s how to build each pattern with the exact nodes n8n gives you.

Step 1: Branch with IF and Switch

Single conditions belong in the IF node (true/false outputs). Three or more outcomes belong in the Switch node (one output per rule, plus a fallback). Practical rules:

  • Put the most common path first — n8n evaluates rules top to bottom.
  • Always wire the fallback output, even if it just logs. Unwired outputs silently drop items, which is the #1 cause of “my workflow lost data” bugs.
  • Prefer one Switch over nested IFs; nested IFs become unreadable after two levels.

Step 2: Bring branches back together with Merge

After parallel branches, the Merge node recombines items. Its modes matter:

  • Append stacks items from all branches into one list (fan-in after parallel API calls).
  • Combine by position or key joins related items, like matching Stripe charges to CRM records.
  • Rename fields before merging so downstream nodes see a consistent schema — use a Set/Edit Fields node on each branch first.

Step 3: Loop over large datasets with Split in Batches

Workflows processing hundreds of rows should not fire 500 parallel HTTP requests. Split in Batches (e.g. batch size 10–20) processes a slice, then loops back via its done vs loop outputs until the input is exhausted. Add a Wait node (1–2 seconds) inside the loop to respect API rate limits, and aggregate results after the loop with Aggregate/Summarize.

Step 4: Reuse logic with sub-workflows

When three workflows all “enrich a lead” or “format a Slack alert,” extract that logic:

  1. Move the shared steps into their own workflow ending with a Respond/return of the result.
  2. Call it from parents with the Execute Workflow Trigger + Execute Sub-Workflow pair.
  3. Version shared sub-workflows carefully — a change propagates to every caller, which is the point, but test with pinned data first.

Sub-workflows also keep the canvas readable: a 60-node canvas is unmaintainable; five 12-node workflows are not.

Step 5: Handle errors like production depends on it (it does)

  • Set per-node On Error behavior: Continue (regular output) for non-critical enrichment, Continue (error output) when you need a fallback branch.
  • Add a global Error Trigger workflow that receives every uncaught failure and notifies you on Slack with the execution URL.
  • For flaky APIs, put the call in a sub-workflow with retry settings (3 attempts, exponential backoff) instead of retrying the whole parent.

Step 6: Test multi-step flows safely

  • Pin data on the trigger so every test run uses the same input.
  • Execute step-by-step with the canvas Execute Step button when debugging branches.
  • Copy the workflow and test against sandbox credentials before touching production — especially for flows that send emails or charge customers.

Skip the boilerplate with templates

Multi-step patterns are easier to learn by reading than by building blind. The collection of free n8n workflow templates includes multi-branch, looping, and sub-workflow examples you can import and dissect node by node — find one close to your use case and adapt its branching structure instead of designing from zero.