Context Window Usage
Calculate what percentage of an LLM's context window your prompt and history consume.
About Context Window Usage
An LLM's context window is the maximum number of tokens (prompt + completion) it can process in a single request. This calculator adds your system prompt and user message/history tokens, then compares the total against the selected model's context window size to show percent used and remaining headroom. Staying well under the limit leaves room for the model's response and avoids truncation errors.
Formula
percent_used = (system_prompt_tokens + user_message_tokens) / context_window_size * 100
- system_prompt_tokens
- Tokens used by the system prompt
- user_message_tokens
- Tokens used by user message and history
- context_window_size
- Maximum tokens supported by the model
Worked example
With the default values below, Context Window Usage returns Context Window Used of 2.73%. Change any input above and every figure here is recalculated in your browser.
Inputs used
- System Prompt Tokensaccepts 0–10,000,000 tokens
- 500 tokens
- User Message / History Tokensaccepts 0–10,000,000 tokens
- 3,000 tokens
- Modelone of GPT-4 (128K), GPT-3.5 Turbo (16K), Claude 3 (200K)
- GPT-4 (128K)
Results
- Context Window Used
- 2.73%
- Remaining Tokens
- 124,500 tokens
- Used Tokens
- 3,500 tokens
- Context Window Size
- 128,000 tokens
Step by step
- 1Total used tokens: system prompt + user message/history= 3500
- 2Percent used: used tokens ÷ context window size= 2.73%
- 3Remaining tokens: context window size − used tokens= 124500
Assumptions and limits
- The result is derived only from the 3 inputs listed above. Anything not among them is not part of the calculation.
- In particular, this calculator does not take inflation, tax, fees or charges or compounding frequency into account.
- Figures are rounded for display to 2 decimal places, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.
How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.
Frequently Asked Questions
What happens if I exceed the context window?
The API will either reject the request with an error or the provider will silently truncate the oldest messages, depending on how your client handles it. It's best to stay under the limit with margin for the response.
Does the completion count against the context window?
Yes. The context window covers both the input (prompt) and the output (completion) combined, so you should reserve tokens for the expected response length.
Why do context windows differ so much between models?
Context window size depends on the model's architecture and how it was trained, particularly its positional encoding scheme and attention mechanism, which determine how much sequence length it can handle reliably.
Should I always use the maximum context window?
Not necessarily — very long contexts increase both cost and latency, and some models show reduced accuracy ('lost in the middle') on very long inputs.
