Context Window Calculator
How much room is left, and what still fits in it.
What the context window actually limits
The window covers input plus output together, not input alone. A 128,000-token model given a 120,000-token prompt cannot produce a 20,000-token answer — there is only room for 8,000. This trips up teams who budget carefully for a large retrieval context and then wonder why long answers get cut off. Always subtract your reserved output before deciding how much input fits: available for input = window − max_tokens − buffer.
Why you need a buffer
Token estimates are approximate, and several things add tokens you did not count: chat templates and special tokens the provider inserts, tool definitions and function schemas, formatting wrappers, and system-level instructions appended automatically. A buffer of three to five percent absorbs this. Without one, you discover the limit by getting a truncation or an API error in production rather than in testing.
Full windows are not fully usable
Models handle material at the beginning and end of a context far better than material in the middle — the "lost in the middle" effect documented across many model families. A 200,000-token window stuffed with retrieved documents often performs worse than a carefully chosen 20,000-token selection from the same source, because relevant passages get lost among irrelevant ones. Retrieval quality beats retrieval quantity: rank and trim rather than concatenating everything that matched.
Strategies when content does not fit
- Trim retrieved passages to the sentences that answer the question, rather than passing whole chunks.
- Summarise older turns instead of replaying the full transcript; keep the last few exchanges verbatim.
- Move stable content to the front so prompt caching applies, which helps cost even though it does not add room.
- Use structured extraction — pull the fields you need from documents first, then answer from the extracted data.
- Chunk and merge for genuinely long documents, processing sections separately and combining the results.
- Shorten the system prompt. Instructions accumulate over months of tweaking and are rarely audited.
Advertised versus effective window
Marketing figures describe the maximum technical window, which is not always the practical one. Some models degrade well before the stated limit; some apply a lower effective limit on certain endpoints; and long-context pricing tiers can make the last portion of the window dramatically more expensive per token. Check your provider's documentation for the effective limit and any long-context surcharge before designing around the headline number. Then verify your real prompt sizes with the token counter and model the spend with the cost calculator.