By Plainly Editorial

Updated

What is a context window in AI?

Filed under AI & modern tech

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

ItemCounts toward the window?Typical size
System promptYesA few hundred to several thousand tokens
Conversation historyYes, resent every turnGrows with each message and reply
Pasted or uploaded documentsYesAbout 1,300 tokens per 1,000 English words
Tool definitions and tool resultsYesHundreds to tens of thousands of tokens
Model reasoning (thinking) tokensYes, in the turn they are generatedVaries; can be large on hard tasks
The model’s replyYesCapped by a separate output limit
Training dataNoStored in the model’s weights, not read per request
  • 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

  1. Context windows — Anthropic
  2. Lost in the Middle: How Language Models Use Long Contexts (Liu et al., 2023) — arXiv
  3. Long context — Google AI for Developers
  4. GPT-4.1 model — OpenAI
  5. Effective context engineering for AI agents — Anthropic

Glossary terms

Keep reading