Answer
How to Create a Sub-Workflow in n8n
Sub-workflows in n8n are reusable workflow components that can be called from other workflows — similar to functions in programming. They promote reusability and keep complex workflows organized.
Creating a Sub-Workflow
Step 1: Create the sub-workflow
- In n8n, create a new workflow
- Add a Workflow Trigger node as the starting point (set it to accept "Execute Workflow" trigger)
- Build the sub-workflow logic
- Use a Set node or Return to define what data to pass back
- Save with a descriptive name like "Send Email Notification"
Step 2: Call it from a parent workflow
Add an Execute Workflow node in your main workflow and select the sub-workflow by name.
n8n Sub-Workflow Types
| Trigger Type | Use Case |
|---|---|
| Execute Workflow | Called by another workflow (synchronous) |
| Webhook | Called via HTTP from any system |
| Schedule | Runs on a schedule independently |
Practical Example
Sub-workflow: "Process Customer Data"
text[Workflow Trigger (Execute Workflow)] ↓ [Validate Input] — check required fields ↓ [Enrich Data] — add timestamp, format name ↓ [Return enriched_customer]
Parent workflow calling it:
text[New Customer webhook arrives] ↓ [Execute Workflow: "Process Customer Data"] Input: {name: "John", email: "john@example.com"} ↓ [Use result: enriched_customer] ↓ [Save to Database] ↓ [Send Welcome Email]
Configuration in n8n
json// Execute Workflow node settings { "workflowId": "xyz123", // ID of sub-workflow "mode": "executeWorkflow", "waitForSubWorkflow": true, // Sync or async "inputData": { "customer": "{{ $json.customer_data }}" } }
Passing Data To/From Sub-Workflows
javascript// In sub-workflow — access input data const inputData = $input.all()[0].json; const customerName = inputData.customer.name; // Return data from sub-workflow (using Set node) return [{ json: { processed: true, enriched_customer: { ...inputData.customer, processed_at: new Date().toISOString(), display_name: customerName.trim() } } }];
Benefits of Sub-Workflows
| Benefit | Description |
|---|---|
| Reusability | Call the same logic from multiple workflows |
| Maintainability | Fix once, applies everywhere |
| Organization | Break complex workflows into smaller pieces |
| Testing | Test sub-workflows independently |
| Permissions | Share sub-workflows across teams |
Best Practices
- Name sub-workflows clearly: "Send Slack Alert", "Validate Email Address"
- Keep sub-workflows focused on ONE task
- Document expected input/output in the workflow description
- Use sub-workflows for any logic used in 2+ places
- Version control your n8n workflows via GitHub integration