What Is a Context Window in an LLM? Context Length Explained
By LatestLLM Editorial · Published · Facts verified · 8 min read
Also called: context length, context size, max tokens, token limit, long context, 128K context
Before this: Token
In one line
A context window is the maximum number of tokens, prompt and reply together, that a language model can take into account at one time.
Context window, simply and technically
In plain English
A language model has no memory of past conversations in the way a person does. Everything it can use when it answers has to be in front of it right now, in the text it is given. The context window is the size of that “in front of it”, counted in tokens. Your question, the earlier messages, any documents you pasted and the answer the model is writing all share the same window.
When a conversation grows past the window, something has to be cut. Chat apps usually drop or summarise the oldest messages. That is why a model can seem to forget the start of a very long chat, and why a bigger window lets you paste a whole report or codebase in a single go.
Think of it like this: A context window is like a desk of a fixed size. Whatever is on the desk, the model can see and use; whatever is off the desk does not exist for it. A bigger desk holds more papers, but it is also harder to keep tidy and slower to search, and the model, unlike a person, cannot reach for papers in a drawer. The desk picture holds until the model runs out of space, when someone has to choose which papers go.
Everyday example: An email thread that does not fit
A 2,000-word email thread is pasted into GPT-2 small, whose window is 1,024 tokens.
Input:
2,000 words ≈ 2,667 tokens
Output:
Window 1,024 tokens: does not fit. Window 131,072 tokens: fits easily.
What it shows: At about three-quarters of a word per token, 2,000 words is roughly 2,700 tokens, more than two and a half times what GPT-2's window can hold. The model could read only the last part of the thread, or an app would have to cut the first part away. Modern models have windows of 131,072 tokens or more, enough for about 98,000 words, a long novel.
Technically
The context window is the maximum sequence length n the model can process, set by its position scheme and by what it was trained on. Input and output tokens share it: a 131,072-token window with a 100,000-token prompt leaves 31,072 for the reply. In published configs the limits are 1,024 for GPT-2 small, 131,072 for gpt-oss, 163,840 for DeepSeek-V3 (its model card states 128K as the tested length), 262,144 for the larger Gemma 4 models and 131,072 for its E2B and E4B sizes. For English, one token is about four characters or three quarters of a word.
Cost grows with length in two ways. Attention compares every token with every earlier one, so a prompt of n tokens needs about n(n+1)/2 query-key pairs per head per layer, and the KV cache that serves generation grows linearly in n. Window size is also not the same as use: Liu et al. (2023) found that performance is often highest when relevant information is at the beginning or end of the input and degrades when it is in the middle, even in models built for long contexts.
Technical example: Counting what a longer window costs
Query-key pairs for causal attention per head per layer, and word equivalents, computed for three window sizes.
Code (python):
WORDS_PER_TOKEN = 0.75 # OpenAI's rule of thumb for English
for name, n in [("GPT-2 small", 1024), ("a mid-size window", 8192), ("gpt-oss", 131072)]:
pairs = n * (n + 1) // 2 # token i reads i + 1 keys
print(f"{name:18s} {n:>7,} tokens ~ {round(n * WORDS_PER_TOKEN):>6,} words, {pairs:>16,} pairs")
n1, n2 = 1024, 131072
print("window grew", n2 // n1, "times; pairs per head grew",
round((n2 * (n2 + 1) // 2) / (n1 * (n1 + 1) // 2)), "times")
Output:
GPT-2 small 1,024 tokens ~ 768 words, 524,800 pairs
a mid-size window 8,192 tokens ~ 6,144 words, 33,558,528 pairs
gpt-oss 131,072 tokens ~ 98,304 words, 8,590,000,128 pairs
window grew 128 times; pairs per head grew 16368 times
What it shows: A window 128 times longer means about 16,000 times more pairwise comparisons for a full pass over the prompt. Optimised kernels avoid storing the n × n table, and sliding windows and sparse attention reduce how many pairs are computed, but the underlying growth is why long windows are expensive.
What counts toward the window
In plain English: Everything the model needs to read counts, and so does everything it writes. A system prompt, the conversation so far, a pasted document, search results, tool outputs and the reply being generated are all tokens in one long sequence. The window is not a per-message limit but a total.
Technically:
Input and output share one budget, so applications reserve room for the answer: a request with max output of 4,096 tokens and a window of 131,072 can carry at most 126,976 input tokens. Reasoning models also spend window on hidden thinking tokens, which can be many times longer than the visible answer.
Tokens are not words. English averages about 0.75 words per token, but code, numbers and non-English text often need more tokens for the same content, so the same page of text can use very different shares of a window depending on language.
What is max output tokens?
A limit on the length of one reply. It is separate from the window, but input plus output must fit inside the window.
Real window sizes
In plain English: Window sizes have grown by about a factor of a hundred in under a decade. GPT-2, released in 2019, could hold about 770 words. Current open models can hold the equivalent of a long novel in one prompt.
Technically:
From the architecture guides: GPT-2 small has a 1,024-token window; gpt-oss-120b and gpt-oss-20b 131,072 (stretched from 4,096 with YaRN); DeepSeek-V3 163,840 positions, with 128K as the tested length; Gemma 4 31B, 26B-A4B and 12B 262,144; Gemma 4 E4B and E2B 131,072. The window is limited by what the model was trained to handle, so extending it means adjusting the position encoding and training on long text.
Models are usually trained with short sequences first, because attention costs grow quickly, and then extended in a final phase. DeepSeek-V3's report describes two extension phases of 1,000 steps each, first to 32K and then to 128K tokens.
What a long window costs
In plain English: A longer window is slower and more expensive to use. The model has to compare more words with each other and keep more notes about them in memory. Providers often charge more, or slow down, for very long prompts.
Technically:
Two resources scale with length. Compute for attention is quadratic in n during prompt processing, so doubling the prompt quadruples that part. Memory for the KV cache is linear in n and often limits how many conversations a GPU can serve at once; at 131,072 tokens gpt-oss-120b needs an estimated 4.8 GB of cache per conversation and DeepSeek-V3 about 9.2 GB.
Architectures target both. Sliding-window layers limit how many tokens most layers read, grouped-query and latent attention shrink the cache, and FlashAttention avoids materialising the n × n score table.
Everyday example: Cost of a long prompt
A provider quotes the same model with a 4,000-token prompt and a 120,000-token prompt.
What it shows: The second prompt is 30 times longer, so there are 30 times as many tokens to process and a cache 30 times larger to hold, and the attention comparisons grow even faster. That is why long-context requests are slower and are priced accordingly by many providers.
Using the window well
In plain English: Having room is not the same as using it well. Models tend to pay most attention to the beginning and end of what they are given and can miss details buried in the middle. People get better results by putting the question near the end, trimming irrelevant text and pulling in only the passages that matter.
Technically:
Liu et al. (2023) tested multi-document question answering and key-value retrieval, and saw accuracy drop when the relevant document moved to the middle of the context, forming a U-shaped curve. Practical consequences include placing instructions and key facts at the start or end and retrieving only the most relevant chunks rather than filling the window.
Retrieval-augmented generation addresses the same issue from the other side: instead of loading a whole library into the window, an index finds the few passages relevant to a question and only those are added to the prompt.
What is lost in the middle?
The finding that language models use information at the start and end of a long input better than information in the middle.
Common misconceptions
Myth: A bigger context window means the model remembers everything forever.
Reality: The window is only what the model can see in the current request. A new conversation starts empty unless an application re-sends or retrieves earlier material.
Myth: The window limits only what you type.
Reality: Your prompt, the model's reply and any hidden reasoning tokens all share the same window.
Myth: If it fits in the window, the model will use all of it equally well.
Reality: Studies find accuracy is often lower for details in the middle of a long input than at the start or end.
Where you'll see this
- gpt-oss architecture: gpt-oss supports 131,072 tokens, stretched from 4,096 with YaRN.
- Gemma 4 architecture: Gemma 4 offers 262,144 tokens in its larger models and 131,072 in E2B and E4B, helped by sliding-window layers.
- DeepSeek-V3 architecture: DeepSeek-V3 allows 163,840 positions and tests to 128K, using latent attention to keep the cache small.
Key takeaways
- The context window is the number of tokens, input and output together, a model can use at once; anything outside it does not exist for the model.
- Real windows range from 1,024 tokens (GPT-2 small) to 131,072 (gpt-oss) and 262,144 (Gemma 4 31B).
- Longer windows cost more: attention work grows with the square of the length and the KV cache grows with it linearly.
- A big window does not guarantee good use of it: models are often worse at using information from the middle of a long input.
Frequently asked questions
What is a context window?
It is the maximum number of tokens, counting both your input and the model's output, that a model can process in one request.
How many words is 128K tokens?
About 98,000 English words (131,072 tokens at three quarters of a word per token), roughly a long novel.
Does the model remember earlier chats?
No. It sees only the tokens in the current window. Apps create the impression of memory by re-sending or retrieving earlier text.
What happens when the window is full?
The request is rejected or the oldest content is dropped or summarised, depending on the application.
Why not make the window unlimited?
Attention compute grows with the square of the length and the KV cache grows linearly, so longer windows cost more, and models must also be trained to use them.
Sources
Facts last verified November 23, 2026.