# Positional encoding

> Canonical: https://skillalmanac.com/glossary/positional-encoding | Last verified: 2026-11-25 | Index status: index-eligible

Positional encoding is information about each token's position in a sequence that a Transformer receives alongside the token itself, because self-attention does not by itself preserve the order of the sequence.

Also called: positional encodings, positional embedding, rotary positional embedding, RoPE, rope embedding, position embedding.

## In plain language

A language model reads words, and word order matters: 'the dog bit the man' differs from 'the man bit the dog'. The attention step inside a Transformer does not by itself keep track of order, so the model is given an extra signal for each word's place in the text. Think of numbering the pages of a loose pile of paper. The model can then learn that the first word and the fifth word relate differently from two neighbours. The limit is that the scheme in use is fixed when the model is built and trained, so behaviour on text much longer than the training text depends on that design and is not guaranteed.

## Technical definition

The original Transformer paper added positional encodings to the input embeddings, using sine and cosine functions of different frequencies; the authors also tried learned positional embeddings and reported nearly identical results, and chose the sinusoidal form because it may allow extrapolation to longer sequences. Later work such as RoFormer proposes rotary position embedding (RoPE), which according to its abstract encodes absolute position with a rotation matrix and incorporates explicit relative position dependency in the self-attention formulation. Absolute, relative and rotary schemes are different designs for the same job.

## How it shows up when you use agents

You do not set positional encoding when you run Claude Code, Codex or Cursor. It shows up indirectly: the model receives your system prompt, files and tool results as one ordered sequence of [tokens](/glossary/token), and the position of each piece is part of what it works with.

What breaks when this is misunderstood is the idea that a bigger [context window](/glossary/context-window) is just more room. The window limit is a property of the service. How well a model uses material far from the question is a separate matter that the sources here do not measure. The Transformer paper says its authors chose the sinusoidal scheme because it may allow extrapolation to longer sequences; that is a design hope, not a guarantee for any model you use.

A useful next step is to test a long-context task on your own files before relying on it, and to keep prompts tidy so that the instructions and material that matter most are easy to find. For the mechanism around this term see [Transformer](/glossary/transformer) and [Attention mechanism](/glossary/attention-mechanism).

## Common confusions

- **Positional encoding versus token embedding.** An [embedding](/glossary/embedding) represents what a token is. Position information represents where it is. In the original design the two are added together.
- **Sinusoidal versus learned.** The original paper tried both and reported nearly identical results, so neither is the definition of the term.
- **Absolute versus relative position.** Absolute schemes mark a token's place in the sequence. Relative schemes describe how far apart two tokens are. RoFormer's abstract says rotary embedding does the first with a rotation matrix and also builds in the second.
- **Position scheme versus context length.** A position scheme is one design choice inside a model. The supported context length is stated by the vendor for a model or service.

## Worked examples in this catalogue

### [What Is an LLM? The Facts Agent Users Need](https://skillalmanac.com/learn/what-is-an-llm-for-agent-users)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: The current guide contrasts the original Transformer decoder's autoregressive generation with BERT's masked pretraining, and distinguishes runtime context from learned parameters.

Why it exercises the concept: Position information is part of how a model handles the ordered tokens inside that window. The guide covers the user-facing side of the window; it does not explain position schemes. Illustrative reading path.

### [context-window-packer](https://skillalmanac.com/skills/skill-almanac/context-window-packer)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: The skill chooses which files fit one prompt's token budget and records what was kept, shrunk or dropped, and why.

Why it exercises the concept: The catalogue has no skill about position encodings themselves, so this is a contrast case about what you control: what goes into the ordered sequence the model reads.

### [local-model-sizing](https://skillalmanac.com/skills/skill-almanac/local-model-sizing)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: The skill works out whether an open-weight language model will run on a given GPU, Mac or PC, with a script that computes weight, KV-cache and overhead memory per quantization.

Why it exercises the concept: Sizing a local model deals with memory, not position schemes. It is a contrast case: the position encoding is part of the model you choose, not a setting this skill adjusts.

## Related terms

- [Transformer](https://skillalmanac.com/glossary/transformer.md)
- [Attention mechanism](https://skillalmanac.com/glossary/attention-mechanism.md)
- [Token](https://skillalmanac.com/glossary/token.md)
- [Embedding](https://skillalmanac.com/glossary/embedding.md)
- [Context window](https://skillalmanac.com/glossary/context-window.md)
- [Large language model (LLM)](https://skillalmanac.com/glossary/large-language-model.md)

## Sources

- [Attention Is All You Need, section 3.5 Positional Encoding (Vaswani et al.)](https://arxiv.org/html/1706.03762v7), arXiv (accessed 2026-11-24)
- [RoFormer: Enhanced Transformer with Rotary Position Embedding](https://arxiv.org/abs/2104.09864), arXiv (accessed 2026-11-24)
- [Self-Attention and Positional Encoding, Dive into Deep Learning](https://d2l.ai/chapter_attention-mechanisms-and-transformers/self-attention-and-positional-encoding.html), d2l.ai (accessed 2026-11-24)

Definitions are written by Skill Almanac from the sources above and checked against them on 2026-11-25. [Glossary index](https://skillalmanac.com/glossary.md).
