AI Tokens and Context Windows Explained for Beginners
Limited working space.
Raju keeps every order slip in a notebook, but only a few fit on his working tray. The notebook holds his records; the tray holds what he is using right now. This gives us a useful starting analogy for an AI conversation: saved history and active context are not the same thing.
Raju’s tea shop is fictional. The AI-generated illustration is a memory aid, not a literal diagram of model operation.
01. What is a token?
A token is a unit a language model uses to represent text. Depending on the tokenizer, it may be a word, part of a word, punctuation, or another text fragment. A tokenizer converts text into token IDs; the model works with numerical representations derived from those IDs.
Text
Your message
Tokenizer
Split and map to token IDs
Model
Process numerical representations
02. Why can one word become several tokens?
A tokenizer has a particular vocabulary and splitting procedure. A familiar word may fit one entry; another word may need several pieces. Spaces, punctuation, capitalization, language, and code can affect counts. Two tokenizers may produce different counts for the same sentence.
un
Beginning of a word
watch
Middle of the word
ed
Ending of the word
03. Input tokens and output tokens
Input tokens represent material supplied to the model for a request. That may include instructions, your question, selected chat history, documents, and tool information. Output tokens are generated by the model. Some services also account for reasoning tokens; visible answer length may not describe the entire output usage.
Input → model
Instructions + question + supplied context
Model → output
Generated response and applicable output usage
04. What is a context window?
A context window is a limit on the tokenized information a model can work with in a request. Think of Raju’s tray as the working space. Many models share a budget across input and generation, while services may also specify separate input and output limits. Check the model’s documentation rather than assuming every service uses identical rules.
Order book
Records saved outside the active task
Working tray
Selected information used now
Space for a reply
Generation budget when shared
05. A simple token-budget example
Imagine a fictional model with a shared 8,000-token limit. Suppose instructions use 500 tokens, selected history uses 2,000, and the question plus documents use 3,500. The input total is 6,000, leaving at most 2,000 tokens for generation under this simplified rule.
Input: 6,000
500 + 2,000 + 3,500
Generation: up to 2,000
8,000 − 6,000
Total ceiling: 8,000
Input and generation together
Allowing 2,000 output tokens does not force the model to use them all. A complete answer might be much shorter. A separate model output limit can also reduce what is available.
06. Why can a long chat lose an earlier detail?
Raju’s notebook can contain more slips than his tray. Likewise, an app can store more conversation than it sends in one model request. It may select recent messages, retrieve relevant facts, or summarize older material. If an important fact is omitted or summarized poorly, the answer may miss it. Even information that fits can be overlooked.
Stored conversation
The app’s available history
Context preparation
Select, retrieve, or summarize
Model request
Only the material actually supplied
07. What happens when the request is too large?
Behavior depends on the API and application. A request may be rejected, or the application may shorten it before sending. Some systems compact context or apply configured truncation. Separately, an answer may stop because it reaches its output limit. These are different situations and need different fixes.
Input/context too large
Reduce or select material; check budget
Output limit reached
Allow a suitable output budget or split the task
08. A larger window does not guarantee a better answer
More capacity can help with long documents, but irrelevant or conflicting material can make a task harder. Raju does not need last year’s entire order book to answer today’s menu question. Choose current, relevant evidence and evaluate whether the model actually uses it correctly.
Keep
Current menu and relevant question
Remove
Duplicates and unrelated history
Check
Did the response use the right facts?
09. Why developers care about tokens
Token counts help developers manage request limits, usage costs, and performance. Many APIs meter input and output separately; caching and other categories can change billing. Longer generation usually adds time, but exact latency depends on the model and infrastructure. Count with the provider’s tools and inspect returned usage instead of guessing from word count.
Before sending
Count or estimate complete input
Budget
Reserve output and relevant overhead
After receiving
Inspect usage and finish status
Try a clearer brief
For a menu assistant, replace a long unrelated conversation with a focused prompt that preserves the facts needed for the task.
Current menu: ginger tea ₹20; masala tea ₹25. Task: compare the prices in one sentence. Use only the supplied menu. If information is missing, say so.
The lesson is not “always make prompts as short as possible.” It is keep enough relevant information to answer correctly, and remove material that does not help.
Check your understanding
1. Does a 100-word paragraph always contain 100 tokens?
No. Token counts depend on the text and tokenizer; words and tokens are different units.
2. Our fictional shared limit is 8,000 tokens and input uses 6,500. What remains?
At most 1,500 tokens in the simplified example, before any additional overhead or separate constraints.
3. If the chat is saved, must the model see every message?
No. The application decides what to include, retrieve, or summarize for the current request.
Tokens are the units the model processes; the context window limits its working space; saved history is what the application stores.
Next lesson
How to Write a Good AI Prompt. We will use task, context, constraints, and examples to turn vague requests into clear instructions.
Join the conversation: What three facts would you keep in the working context of Raju’s menu assistant?
- Google: Language models and tokens
- Google: Understand and count tokens
- Claude: Context-window documentation
- Firebase: Count tokens and inspect usage
Limits and accounting vary by model and service. The 8,000-token budget is a fictional teaching example.
Comments
Post a Comment