Context Window Usage
Calculate what percentage of an LLM's context window your prompt and history consume.
Inputs
Context Window Used
2.73%
Remaining Tokens
124,500tokens
Used Tokens
3,500tokens
Context Window Size
128,000tokens
Step by step
Total used tokens: system prompt + user message/history
500 + 3000
= 3500
Percent used: used tokens ÷ context window size
3500 ÷ 128000
= 2.73%
Remaining tokens: context window size − used tokens
128000 − 3500
= 124500
How it works
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
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.