AI/TLDR

How Is a Context Window Measured? Tokens, Not Words or Pages

Learn exactly what fills a context window: every token of your system prompt, chat history, attached files, and the reply all share the same budget.

BEGINNER8 MIN READUPDATED 2026-06-13

In plain English

When a model advertises a 128K context window, that 128,000 number is not words, characters, or pages. It is tokens — the small chunks a large language model actually reads. A token is usually a short piece of a word: common words like the are one token, while a longer word like unbelievable might split into two or three. As a rough rule of thumb in English, one token is about 4 characters, or about ¾ of a word.

Measuring the Window — illustration
Measuring the Window — engineeringdiscoveries.com

Think of the context window as a fixed-size desk. Everything the model needs to look at for this one reply has to fit on the desk at the same time: the instructions, the conversation so far, any files you pasted in, and the space the model needs to write its answer. When the desk is full, something has to come off — there is no overflow tray. Measuring the window simply means counting how many tokens are currently sitting on that desk.

Why it matters

If you build with LLMs, the context window is a hard budget you are spending on every single call — and the bill is paid in tokens, not in your intuition about length. Two things make this matter in practice.

  • You get charged and rate-limited by the token. API pricing is per million tokens for input and (separately, usually more expensive) for output. A request that feels short can be huge once you count the system prompt, the whole chat history, and a 40-page PDF you attached. Knowing the count is knowing the cost.
  • You hit the ceiling silently. Go over the limit and the request either errors out or quietly drops the oldest messages — and the model forgets what you told it earlier. People are constantly surprised because they only count their latest message and forget that history accumulates.
  • Bigger isn't free. Even when everything fits, every token is read on every call, which costs latency and money, and models recall facts buried in a very long window less reliably — the lost-in-the-middle effect. Measuring lets you keep the window lean on purpose.

This article is the practical accounting side of the topic. If you want the concept itself — what a context window is and why models have one — start with what is a context window. Here we answer the builder's question: what exactly counts toward the limit, and how do I count it?

How it works

The model never sees your raw text. Before anything happens, a tokenizer splits your text into tokens and maps each one to a number. The context window limit is a count of those numbers. So the real measuring unit is the tokenizer's output, which is why the same sentence can cost a different number of tokens in different models — each model family has its own tokenizer.

From text to a token count

Here is the part people miss: the window holds everything for this turn at once, input and output. The total you must stay under is roughly: system prompt + every earlier message in the conversation + tool/function call results + attached files + your new message + the space reserved for the model's reply. If the model is allowed to write up to 4,000 tokens, those 4,000 are subtracted from your budget before it writes a single word.

What shares the budget

Add those layers up and you have your token count for the call. Stay under the model's window and it works; cross it and you must drop, summarize, or retrieve instead of pasting. Counting the layers — not just your latest message — is the whole skill.

Counting tokens in practice

You don't have to guess. Every major provider ships a way to count tokens before you send, so you can check a prompt against the limit and estimate cost. The numbers below are the standard English heuristics — handy for a back-of-the-envelope estimate when you can't run the tokenizer.

You haveRough tokensWhy it's only rough
1 word (English)~1.3 tokensShort words are 1 token; long/rare words split into several
1 page (~500 words)~650 tokensDepends on formatting, headers, whitespace
1,000 tokens~750 wordsThe reverse of the rule above
Code or JSONmore tokens/charBraces, indentation, and symbols each cost tokens
Non-English textmore tokens/wordTokenizers are tuned mostly for English

For an exact count, call the provider's token-counting endpoint. With the Claude API you can measure a full request — system prompt, messages, and tools — before sending it, so you know the input size precisely:

count tokens before sending (Claude API)python
from anthropic import Anthropic

client = Anthropic()  # reads ANTHROPIC_API_KEY from the environment

result = client.messages.count_tokens(
    model="claude-sonnet-4-6",
    system="You are a concise support assistant.",
    messages=[
        {"role": "user", "content": "Summarize our refund policy in two sentences."},
    ],
)

print(result.input_tokens)  # exact input-token count for THIS request
# Compare against the model's context window before you call .create(...)

How people accidentally blow the limit

Almost every "context length exceeded" surprise comes from counting one part of the request and forgetting the rest. The classic traps:

  • Forgetting history accumulates. In a chat, the entire prior conversation is resent on every turn — that's how the model "remembers." Turn 1 might be 500 tokens; by turn 30 the same window holds tens of thousands. Your newest message is tiny, but the request is enormous.
  • Counting words, not tokens. A 90,000-word manuscript sounds like it fits in a 128K window. It's roughly 120K tokens of input — and once you add a system prompt and reserve output space, it overflows.
  • Pasting whole files. A single attached PDF or a long log file can be 20–50K tokens by itself. Attachments and retrieved chunks count exactly like typed text.
  • Ignoring tool outputs. Agents that call search or APIs dump big JSON blobs back into the context. Those results count too, and they can dwarf the user's question.
  • Forgetting the reply needs room. If the window is full of input, there's no space left for the answer — the model can't write a 1,000-token reply if only 200 tokens of budget remain.

Going deeper

A few nuances matter once the basics click.

Tokenizers differ between models. "128K" in one model and "128K" in another are both 128K tokens, but the same sentence may tokenize to different counts because each family uses its own tokenizer. So you can't reuse one model's token count for another — always measure with the tokenizer of the model you'll actually call.

Input and output limits can be separate. The context window is the total budget, but many models also cap how many tokens they'll generate in one reply (a max_tokens setting), which is smaller than the full window. A model can have a 200K window yet refuse to write more than, say, a few thousand tokens at once. Both limits are real; plan for the tighter one.

Non-text content has a token cost too. Images, audio, and PDFs sent to multimodal models are converted into tokens internally — a high-resolution image can cost hundreds to over a thousand tokens. They consume the same window as text, even though you never typed a word.

A bigger window doesn't make counting optional. Even with million-token context windows, every token is paid for on every call and recall degrades for facts buried deep in a long prompt. The professional move is to keep the window lean: summarize old turns, retrieve only the passages you need instead of pasting whole documents, and trim tool outputs. Measuring is how you know whether you're winning that fight.

Where to go next: see how the context window differs from what the model learned in training in context vs training data, and the bigger picture of how LLMs work under the hood.

FAQ

How is a context window measured — in words or tokens?

In tokens, not words or characters. A token is a small chunk of text, usually about ¾ of an English word or roughly 4 characters. So a 128K context window means 128,000 tokens, which is about 96,000 words of normal English.

What counts toward the context window?

Everything the model reads for one reply shares the budget: the system prompt, the entire conversation history, any tool or function-call outputs, attached files and retrieved chunks, your latest message, and the space reserved for the model's own answer. People usually count only their latest message and overflow without realizing it.

Does the output count against the context window?

Yes. The window is one shared budget for input and output combined. The tokens the model is allowed to generate are reserved from the same limit before it writes anything, so if the input nearly fills the window, there's little room left for a reply.

How many pages is a 128K context window?

Roughly 300 pages of normal text. 128,000 tokens is about 96,000 words, and a typical page holds around 300–500 words. Code, tables, and non-English text pack more tokens per page, so the real number will be lower for dense content.

Why does the same text use a different number of tokens in different models?

Because each model family has its own tokenizer — the tool that splits text into tokens. The splitting rules differ, so the identical sentence can produce different token counts. Always count with the tokenizer of the specific model you plan to call.

How do I count tokens before sending a request?

Use the provider's token-counting tool. For example, the Claude API has a count_tokens method that measures a full request (system prompt, messages, and tools) and returns the exact input-token count, so you can compare it against the model's window before you send.

Further reading