> 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/work-with-data/reference-data/link-data-items/how-items-link-through-workflows.md).

# How items link through workflows

Each output item created by a node includes metadata that links them to the input item (or items) that the node used to generate them. This creates a chain of items that you can work back along to access previous items. This can be complicated to understand, especially if the node splits or merges data. You need to understand item linking when building your own programmatic nodes, or in some scenarios using the Code node.

This document provides a conceptual overview of this feature. For usage details, refer to:

* [Item linking for node creators](/build/work-with-data/reference-data/link-data-items/item-linking-for-node-creators.md), for details on how to handle item linking when building a node.
* [Preserving linking in the Code node](/build/work-with-data/reference-data/link-data-items/preserving-linking-in-the-code-node.md), to learn how to handle item linking in the Code node.
* [Item linking errors](/build/work-with-data/reference-data/link-data-items/item-linking-errors.md), to understand the errors you may encounter in the editor UI.

## n8n's automatic item linking <a href="#n8ns-automatic-item-linking" id="n8ns-automatic-item-linking"></a>

If a node doesn't control how to link input items to output items, n8n tries to guess how to link the items automatically:

* Single input, single output: the output links to the input.
* Single input, multiple outputs: all outputs link to that input.
* Multiple inputs and outputs:
  * If you keep the input items, but change the order (or remove some but keep others), n8n can automatically add the correct linked item information.
  * If the number of inputs and outputs is equal, n8n links the items in order. This means that output-1 links to input-1, output-2 to input-2, and so on.
  * If the number isn't equal, or you create completely new items, n8n can't automatically link items.

If n8n can't link items automatically, and the node doesn't handle the item linking, n8n displays an error. Refer to [Item linking errors](/build/work-with-data/reference-data/link-data-items/item-linking-errors.md) for more information.

## Item linking example <a href="#item-linking-example" id="item-linking-example"></a>

![A diagram showing the threads linking multiple items back through a workflow](/files/xH7Lllo09KJNNsJRMAQQ)

In this example, it's possible for n8n to link an item in one node back several steps, despite the item order changing. This means the node that sorts movies alphabetically can access information about the linked item in the node that gets famous movie actors.

The methods for accessing linked items are different depending on whether you're using the UI, expressions, or the code node. Explore the following resources:

* [Mapping in the UI](/build/work-with-data/reference-data/use-the-ui-mapper.md)
* [Preserving linking in the Code node](/build/work-with-data/reference-data/link-data-items/preserving-linking-in-the-code-node.md)
* [Item linking errors](/build/work-with-data/reference-data/link-data-items/item-linking-errors.md)


---

# 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/work-with-data/reference-data/link-data-items/how-items-link-through-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.
