Explainer
What is a context window in AI?
What does “context window” actually mean?
A large language model (LLM) does not remember past chats the way a person does. Each time you send a message, the app packages up everything the model needs to see and sends it as one block of text. The context window is the size limit on that block.
Think of it as the model’s working memory, or a desk of fixed size. Whatever fits on the desk can be read and used. Whatever does not fit has to be left off, summarized, or fetched again later. The model’s training data is separate: that is long-term knowledge baked into its weights, not something it reads at request time.
The limit is measured in tokens, not words. A token is a chunk of text, often a word or part of a word. In English, 1,000 words is roughly 1,300 tokens with typical tokenizers, so a 200,000-token window holds about 150,000 words.
What counts toward the context window?
Everything the model reads or writes in a single turn counts. Anthropic’s documentation spells this out: the system prompt, every message in the conversation (including tool results, images and documents), the tool definitions, and the output the model generates, including any hidden reasoning or “thinking” tokens.
That has a practical consequence. If a model has a 200,000-token window and your prompt already uses 190,000 tokens, it only has about 10,000 tokens left to answer. Long chats fill up surprisingly fast because every earlier message and reply is resent each turn.
Hidden items also take space. Tool and function descriptions, retrieved web pages, file attachments and formatting instructions added by the app all consume tokens, even if you never see them.
What happens when you exceed the context window?
It depends on the product. Through an API, a request whose input is larger than the window is usually rejected with an error such as “prompt is too long.” If the input fits but the answer runs out of room, generation stops early and the response is cut off.
Chat apps handle it more quietly. Many drop or summarize the oldest messages so the conversation can continue. This is why a long chat can seem to “forget” instructions you gave at the start: those messages may no longer be in the window at all.
Some platforms now offer automatic compaction, where earlier parts of a conversation are summarized on the server so work can continue. Summaries save space but lose detail, so precise facts from early in the chat are worth restating.
How big are context windows in late 2026?
Sizes have grown quickly. As of late 2026, leading models from Anthropic, Google and OpenAI commonly offer windows between about 400,000 and 1 million tokens through their APIs. Anthropic lists a 1-million-token window for its current Claude models, Google’s Gemini documentation describes windows of 1 million tokens or more, and OpenAI lists about 1 million tokens for GPT-4.1 and 400,000 for GPT-5.
Older and smaller models typically sit between 128,000 and 200,000 tokens. Small open-weight models you run on your own computer are often configured far lower, because memory use grows with context length.
Two caveats. First, consumer chat apps sometimes give you less than the full API limit. Second, the output limit is separate and much smaller: a model with a 1-million-token window may still cap a single reply at tens of thousands of tokens.
Does a bigger context window mean better answers?
Not automatically. A well-known 2023 study by Nelson Liu and colleagues at Stanford, “Lost in the Middle,” found that models were best at using information placed at the very start or end of a long prompt and noticeably worse when the key fact sat in the middle. The effect showed up even in models designed for long inputs.
Providers acknowledge a related problem. Anthropic’s documentation calls it “context rot”: as the token count grows, accuracy and recall gradually degrade. A window is a ceiling on what can be read, not a promise that all of it will be used well.
The practical lesson is to curate. Put the most important instructions and facts near the start or end, remove irrelevant material, and avoid pasting entire folders when one file would do.
Long context vs RAG: which should you use?
Retrieval-augmented generation (RAG) is the main alternative to stuffing everything into the window. Instead of sending a whole knowledge base, a RAG system searches it, picks the few passages most relevant to the question, and adds only those to the prompt.
Long context is simpler and works well when the material is small enough to fit and you need the model to see all of it, such as reviewing one contract or one codebase module. RAG is better when the source material is far larger than any window, changes often, or must be cheap to query thousands of times a day, because you pay for every token you send.
Many real systems combine both: retrieval narrows the search, and a generous window lets the model read the retrieved documents in full rather than in tiny fragments.
How can you work within a context window?
Start a new chat when you switch topics, so old messages are not crowding the window. Summarize long threads yourself and paste the summary into a fresh conversation.
Trim documents to the relevant sections, and put your actual question at the end, after the material. For developers, count tokens before sending a request, cache stable prompt prefixes to save cost, and clear old tool results in long-running agents.
What a context window holds, with rough token costs
| Item | Counts toward the window? | Typical size |
|---|---|---|
| System prompt | Yes | A few hundred to several thousand tokens |
| Conversation history | Yes, resent every turn | Grows with each message and reply |
| Pasted or uploaded documents | Yes | About 1,300 tokens per 1,000 English words |
| Tool definitions and tool results | Yes | Hundreds to tens of thousands of tokens |
| Model reasoning (thinking) tokens | Yes, in the turn they are generated | Varies; can be large on hard tasks |
| The model’s reply | Yes | Capped by a separate output limit |
| Training data | No | Stored in the model’s weights, not read per request |
Examples
- A 300-page novel of about 90,000 words is roughly 120,000 tokens, so it fits inside a 200,000-token window with room for questions.
- A support chatbot with a 3,000-token system prompt and a 40-message history may already be using 15,000 tokens before the user’s new question.
- A coding agent that reads 20 large files and logs every test run can fill a 1-million-token window over a long session unless old tool output is cleared.
- If you paste a 50-page report and ask about a figure on page 25, restating the figure near your question improves reliability because of the lost-in-the-middle effect.
- A company help center with 2 million words of articles is too big for most windows, so a RAG system retrieves the five most relevant articles per question instead.
Common questions
Is the context window the same as the model’s memory?
Only short-term memory. The window holds what the model can see in the current request. Some apps add a separate memory feature that saves facts between chats and inserts them into future prompts, but those saved facts still have to fit inside the window to be used.
Do images and PDFs count toward the context window?
Yes. Images and PDF pages are converted into tokens too, and a single page or image can cost hundreds to over a thousand tokens. Providers may also set separate limits on how many images or pages a single request can include.
Why does a long context cost more?
API pricing is per token, and the whole conversation is resent each turn. A chat that has grown to 100,000 tokens costs roughly 100,000 input tokens for every new message. Prompt caching can reduce the price of repeated content but does not stop it occupying the window.
Can I increase a model’s context window?
Not as a user of a hosted model; the provider sets the limit. You can choose a model with a larger window, or use techniques such as summarization and retrieval to fit more useful information into the space you have. Self-hosted open models can sometimes be configured for longer context, at the cost of more memory.
What is the difference between the context window and max output tokens?
The context window is the total budget for input plus output in one request. Max output tokens is a separate, smaller cap on how long the reply alone can be. A model can have a 1-million-token window but still limit a single answer to a much smaller number of tokens.
Sources and further reading
- Context windows — Anthropic
- Lost in the Middle: How Language Models Use Long Contexts (Liu et al., 2023) — arXiv
- Long context — Google AI for Developers
- GPT-4.1 model — OpenAI
- Effective context engineering for AI agents — Anthropic
Glossary terms
- Context window
A context window is the maximum amount of text, measured in tokens, that an AI model can work with in a single request. It covers everything at once: instructions, conversation history, attached documents and the model’s own reply. Anything beyond the limit must be cut or summarised.
- Token
In AI, a token is the small unit of text a language model reads and writes. A token can be a whole word, part of a word, a punctuation mark or a space. In English, one token averages about four characters, or roughly three-quarters of a word.
Keep reading
- AI model comparison (free tool)
Every major language model side by side: context window, price per million tokens, and whether you can download it.
- What are tokens in AI?
Tokens are the small chunks of text that AI language models read and write, usually a whole short word, part of a longer word, or a punctuation mark. In English, one token averages about four characters or three-quarters of a word. Tokens matter because AI pricing, speed, and context-window limits are all measured in them.
- How many tokens is 1,000 words?
1,000 English words is roughly 1,300 to 1,400 tokens. The common rule of thumb, from OpenAI’s guidance, is that one token is about three-quarters of a word, or about four characters of English text. Exact counts vary by model, language and content type, so use a tokenizer or token-counting API when precision matters.
- What is RAG?
RAG (retrieval-augmented generation) is a technique where an AI system first searches a set of documents for passages relevant to your question, then gives those passages to a language model to write the answer. It lets the model use current, private, or specialized information it was never trained on, and makes answers easier to check against sources.
- What is an LLM?
An LLM (large language model) is an AI system trained on huge amounts of text to predict the next piece of a sentence. By doing that prediction billions of times, it learns grammar, facts, and patterns of reasoning well enough to answer questions, write, summarize, translate, and generate code. Chatbots like ChatGPT and Claude are built on LLMs.
- Prompt vs context engineering
Prompt engineering is the craft of wording instructions so a model understands the task. Context engineering is the wider job of deciding everything the model sees on each call: system prompt, retrieved documents, tool definitions and results, memory, examples, and conversation history, all within a limited context window. Prompt engineering is one part of context engineering.
- What is a system prompt?
A system prompt is a set of instructions given to an AI model before the conversation starts, telling it who it is, what it should do and how it should behave. Users usually never see it. It sets the role, tone, rules and background knowledge, while user prompts are the individual questions or requests that follow.