If you're building or fine-tuning LLMs, understanding positional encoding pays off directly when you hit context-window limits. The core problem: self-attention is order-blind. Feed a model "The red fox jumps over the gray fox" versus the same words reshuffled, and a plain attention mechanism produces identical embeddings and attention scores for matching token pairs. Without a position signal, the model can't tell which fox does the jumping.
Causal (autoregressive) masking in GPT-style models leaks some order information for free, since each token only attends to itself and earlier tokens. That's enough to theoretically distinguish the two fox sentences. But the mask doesn't encode distance—it can't tell a one-token gap from a ten-token gap—so most models add explicit positional information anyway. This is also the foundation of the "NoPE" idea, where some architectures lean on that implicit signal and skip explicit encoding entirely.
GPT-2 uses the simplest approach: a learned table of absolute position vectors, added element-wise to token embeddings before the first transformer block. Position 0 gets its own vector, position 1 gets another, and so on. The practical catch is cost. GPT-2's table holds 1,024 positions, which decides the maximum context before training even starts. In GPT-2 Medium, that table is just 0.30% of total weights—but scale the context to today's 100k range and it balloons to over 22% of the model. That's why nobody extends context this way anymore.

The original 2017 "Attention Is All You Need" transformer used the same additive mechanism but computed position vectors with fixed sine and cosine functions instead of learned weights. It also scaled token embeddings by the square root of the embedding width before adding positions—an undocumented detail that likely keeps token and position vectors on comparable numerical scales at initialization, so positions don't dominate the sum. GPT-2 sidestepped that by initializing token embeddings with a 0.02 standard deviation and position embeddings with 0.01.
Those sine and cosine functions resurface in RoPE (rotary positional embeddings), the method behind most 2026 open-weight models. Rather than adding a position vector once at the input, RoPE injects relative position information inside attention at every transformer block by rotating query and key vectors. That's the shift worth internalizing: modern architectures moved from absolute, learned-at-input encodings toward relative, per-block methods—or in the NoPE case, dropping explicit encoding altogether—largely to escape the context-scaling tax that fixed embedding tables impose.
The takeaway for builders: if you're choosing or adapting an architecture, your positional method constrains how far you can push context length and how cheaply. Learned absolute embeddings lock you into a fixed window; RoPE and relative methods give you room to extrapolate. Knowing the mechanism tells you which knobs to turn when a model refuses to generalize past its trained context.
