Skip to content

Context Window Calculator

Plan an LLM token budget: system prompt, tools, chat history, retrieved documents and reserved output against the context window.

Calculator Details

Tokens left:169,800See results ↓

The model's context window in tokens (from its documentation): 128,000, 200,000 and 1,000,000 are common sizes.

max_tokens for the answer (include thinking tokens if the model counts them in the window).

Tokens in the instructions sent with every request.

Tokens for function/tool schemas sent with the request (0 if none).

Earlier user + assistant exchanges kept in the prompt.

Average tokens for one user message plus one reply.

Retrieved passages or files added to the prompt (RAG).

Average size of one chunk in tokens.

Tokens in the user's new question.

Your Results

Tokens left: 169,800

Tokens left

169,800

10.1% of the 200,000-token window used

Input tokens

16,200

+ 4,000 reserved for the reply

More document chunks that fit

212

Conversation turns that fit

293

In total, with everything else unchanged

Usable budget

190,000

After a 10,000-token safety margin

The request uses 20,200 of 200,000 tokens (10.1%), leaving 169,800 after the safety margin: room for 212 more document chunks, or up to 293 conversation turns in all.

Compare scenarios

Save these inputs as a scenario, change them, and compare the results side by side.

Loading, available in a moment

How the context window is used

How the context window is used

Detailed Breakdown

Token budget by part
PartTokensShare of window
System prompt2,0001%
Tool definitions1,5000.75%
Conversation history6,0003%
Documents (RAG)6,4003.2%
New message3000.15%
Reserved for the reply4,0002%
Safety margin10,0005%
Still free169,800

How This Calculator Works

How the budget is calculated

input = system + tools + turns × tokens per turn + chunks × tokens per chunk + message

left = window × (1 − margin) − input − reserved output

input = 2,000 + 1,500 + 10 × 600 + 8 × 800 + 300 = 16,200

left = 190,000 − 16,200 − 4,000 = 169,800

The reply's maximum length counts against the window at most providers, so it is reserved up front. Token counts depend on each model's tokenizer; the safety margin absorbs the difference and the few tokens each message's formatting adds.

Frequently Asked Questions

What is a context window?

The maximum number of tokens a language model can handle in one request: everything it reads (instructions, tools, the conversation so far, documents, your question) plus, at most providers, the reply it writes. Anything beyond the limit is rejected or has to be cut.

Does the reply count against the context window?

At most providers, yes: the input plus the maximum output (max_tokens) must fit in the window, so the calculator reserves the reply’s length up front. Some models also count reasoning ("thinking") tokens in that reply budget. Check your model’s documentation for its exact rule.

How many words fit in 200,000 tokens?

Roughly 150,000 English words, at about three quarters of a word per token. That is a long novel or several hundred pages. Code, numbers, tables and many other languages use more tokens per word, so the real figure is often lower.

How do I count the tokens in my prompt?

Use your provider’s token-counting endpoint or tokenizer library, or read the usage numbers returned with each response. This calculator does not run a tokenizer (each model counts differently); it adds up the counts you enter.

How much conversation history should I keep?

As much as fits after the system prompt, tools, documents, the new message and the reply. The calculator’s “conversation turns that fit” shows the ceiling. Long chats usually trim the oldest turns or replace them with a short summary.

Why keep a safety margin?

Token counts are estimates until the provider tokenizes the request, and each message adds a few formatting tokens. A margin of a few percent avoids requests that fail at the limit. Set it to 0 if your counts come from the provider’s own counter.

Is a bigger context always better for RAG?

Not always. More chunks cost more (every input token is billed) and slow the first token down, and models can miss details buried in a very long prompt. Many systems retrieve fewer, better-ranked chunks rather than filling the window.

A token budget from the counts you enter: input parts plus the reserved reply against the window, less a safety margin. No tokenizer runs here, because each model counts tokens differently. Not included: images, audio and file attachments, output limits that some models keep outside the window, provider rules for reasoning tokens, and per-message formatting tokens (the margin stands in for them).

Context Window Calculator: Plan an LLM Token Budget

By FindMySum · Last reviewed

A context window calculator plans the token budget of a single request to a large language model. The context window is the most text, measured in tokens, that the model can work with at once: the instructions, the tool definitions, the conversation so far, any documents you retrieve, the new question and, at most providers, the reply itself. This page adds up the parts you enter, keeps a safety margin, and tells you how much room is left and how many more document chunks or conversation turns would fit. The worked example uses the defaults: a 200,000-token window, a chat with ten earlier turns and eight retrieved chunks.

What goes into the window

PartWhat it isGrows with
System promptStanding instructions for every requestRarely changes
Tool definitionsNames, descriptions and schemas of functions the model may callNumber of tools
Conversation historyEarlier user messages and repliesEvery turn
DocumentsRetrieved passages (RAG), files, search resultsChunks × chunk size
New messageThe user's current question—
Reserved replyThe maximum output you allowYour max_tokens setting

The reply is reserved up front because most providers check that the input plus the maximum output fits before they start. Reasoning ("thinking") tokens usually count in that reply budget.

The formula

input = system + tools + turns × tokens per turn + chunks × tokens per chunk + message

left = window × (1 − safety margin) − input − reserved reply

From what is left, the calculator also works out how many more chunks of the same size would fit, and how many conversation turns in total would fit with everything else unchanged.

Worked example

  1. Input: 2,000 + 1,500 + 10 × 600 + 8 × 800 + 300 = 16,200 tokens.
  2. With the reply reserved: 16,200 + 4,000 = 20,200 tokens, 10.1% of the window.
  3. Usable budget: 200,000 less a 5% margin = 190,000 tokens.
  4. Left: 190,000 − 20,200 = 169,800 tokens.
  5. More chunks: 169,800 ÷ 800 = 212 (rounded down).
  6. Turns in total: (190,000 − 14,200) ÷ 600 = 293.

This request uses a tenth of a large window. The same request against a 32,000-token window with 40 chunks would need 45,800 tokens against a budget of 30,400, and fail by 15,400.

Why a safety margin?

Token counts depend on the model's tokenizer, and the same text can differ by several percent between models. Each message also carries a few formatting tokens that are easy to forget. A margin of a few percent absorbs both. If your counts come from the provider's own token counter for the exact request, you can set the margin to zero.

Counting tokens

This page does not run a tokenizer, because each model family has its own. Three ways to get real counts:

  • read the input and output token counts the API returns with every response;
  • call the provider's token-counting endpoint before sending;
  • use the model's tokenizer library on your text.

As a rough guide, English prose runs about three quarters of a word per token, so 1,000 tokens is around 750 words. Code, tables, numbers and many other languages use more tokens per word.

Budgeting tips

  • Trim history first. Old turns are the part that grows without limit; keep the last few and summarise the rest.
  • Retrieve less, rank better. Eight well-chosen chunks usually beat forty loosely related ones, and cost less.
  • Size the reply honestly. A maximum of 4,000 tokens reserves 4,000 tokens even if the answer uses 300; set it near what the task needs.
  • Remember the bill. Every input token is charged; the LLM cost calculator shows what this budget costs per request and per month.

More questions

What happens when a request is longer than the context window?

Most APIs reject it with an error that names the limit; some chat products silently drop the oldest messages instead. Either way the model never sees what did not fit, so plan the budget before the request rather than after the error.

Should I fill the whole context window?

Rarely. Every input token is billed and slows the first token down, and answers can get worse when the relevant passage is buried among many others. A budget that leaves room is cheaper and often more accurate.

How big should RAG chunks be?

Common choices run from about 200 to 1,000 tokens per chunk, with some overlap between neighbours. Smaller chunks let you fit more distinct sources; larger ones keep more context around each fact. Try a few sizes on your own questions and measure answer quality.

Do tool definitions really take that many tokens?

They can. Each tool's name, description and JSON schema is sent with every request, and a set of twenty detailed tools can run to several thousand tokens. Check the input token count of a request with tools and without to see your figure.

Does the context window include images?

Yes, at providers that accept images, each image is converted to tokens that count against the window, often hundreds to a few thousand per image depending on its size. This calculator covers text; add your image token estimate to the message or documents line.

Sources

This article explains how the calculator works and is general information, not financial, tax, legal or medical advice. Rules change; check the sources above or a qualified professional before you act.

Spotted a wrong result or a bug? Report a problem

May we count your visits with Invoker Analytics? It keeps a random visitor number in your browser. Your calculator inputs are never sent. Privacy policy