> For the complete documentation index, see [llms.txt](https://docs.n8n.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.n8n.io/build/flow-logic/convert-to-sub-workflows.md).

# Convert to sub-workflows

{% hint style="info" %}
**Feature availability**

Available on all plans from n8n version 1.97.0.
{% endhint %}

Use sub-workflow conversion to refactor your workflows into reusable parts. Expressions referencing other nodes are automatically updated and added as parameters in the [Execute Workflow Trigger](/integrations/builtin/core-nodes/n8n-nodes-base.executeworkflowtrigger.md) node.

See [sub-workflows](/build/flow-logic/break-workflows-into-smaller-parts.md) for a general introduction to the concept.

## Selecting nodes for a sub-workflow <a href="#selecting-nodes-for-a-sub-workflow" id="selecting-nodes-for-a-sub-workflow"></a>

To convert part of a workflow to a sub-workflow, you must select the nodes in the original workflow that you want to convert.

Do this by selecting a group of valid nodes. The selection must be continuous and must connect to the rest of the workflow from at most one start node and one end node. The selection must fulfill these conditions:

* Must not include trigger nodes.
* Only a single node in the selection can have incoming connections from nodes *outside* of the selection.
  * That node can have multiple incoming connections, but only a single input *branch* (which means it can't be a [Merge node](/integrations/builtin/core-nodes/n8n-nodes-base.merge.md) for example).
  * That node can't have incoming connections from other nodes in the selection.
* Only a single node in the selection can have outgoing connections to nodes *outside* of the selection.
  * That node can have multiple outgoing connections, but only a single output branch (it can't be an [If node](/integrations/builtin/core-nodes/n8n-nodes-base.if.md) for example).
  * That node can't have outgoing connections to other nodes in the selection.
* The selection must include all nodes between the input and output nodes.

## How to convert part of a workflow to a sub-workflow <a href="#how-to-convert-part-of-a-workflow-to-a-sub-workflow" id="how-to-convert-part-of-a-workflow-to-a-sub-workflow"></a>

Select the desired nodes on the canvas. Right-click the canvas background and select **Convert to sub-workflow**.

## Things to keep in mind <a href="#things-to-keep-in-mind" id="things-to-keep-in-mind"></a>

Most sub-workflow conversions work without issues, but there are some caveats and limitations to keep in mind:

* **You must set type constraints for input and output manually**: By default, sub-workflow input and output allow all types. You can set expected types in sub-workflow's [Execute Sub-workflow Trigger node](/integrations/builtin/core-nodes/n8n-nodes-base.executeworkflowtrigger.md) and [Edit Fields (set) node](/integrations/builtin/core-nodes/n8n-nodes-base.set.md) (labeled as **Return** and only included if the sub-workflow has outputs).
* **Limited support for AI nodes**: When dealing with sub-nodes like AI tools, you must select them all and may need to duplicate any nodes shared with other AI Agents before conversion.
* **Uses v1 execution ordering:** New workflows use [`v1` execution ordering](/build/flow-logic/understand-execution-order.md) regardless of the parent workflow's settings - you can change this back in the settings.
* **Accessor functions like `first()`, `last()`, and `all()` require extra care**: Expressions using these functions don't always translate cleanly to a sub-workflow context. n8n may transform them to try to preserve their functionality, but you should check that they work as intended in their new context.<br>

  <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p><strong>Sub-node parameter suffixes</strong></p><p>n8n adds suffixes like <code>_firstItem</code>, <code>_lastItem</code>, and <code>_allItems</code> to variable names accessed by these functions. This helps preserve information about the original expression, since item ordering may be different in the sub-workflow context.</p></div>
* **The `itemMatching` function requires a fixed index**: You can't use expressions for the index value when using the [`itemMatching` function](/build/work-with-data/reference-data/reference-previous-nodes.md). You must pass it a fixed number.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.n8n.io/build/flow-logic/convert-to-sub-workflows.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
