AI Tokens and Context Windows Explained for Beginners

AI BASICS TO ADVANCED · LESSON 05
Small pieces.
Limited working space.
Understand tokens, context windows, and what reaches the model.

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 BECOMES MODEL INPUT
01
Text
Your message
02
Tokenizer
Split and map to token IDs
03
Model
Process numerical representations
Do not assume one token equals one word. The exact split depends on the tokenizer.

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.

A POSSIBLE SPLIT · NOT A MEASURED COUNT
01
un
Beginning of a word
02
watch
Middle of the word
03
ed
Ending of the word
“unwatched” → “un” + “watch” + “ed” is an illustrative split. Use the chosen model’s tokenizer or counting tool for the actual result.

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.

TWO DIRECTIONS
01
Input → model
Instructions + question + supplied context
02
Model → output
Generated response and applicable output usage
A previous answer can become part of the input on a later turn if the application sends it again.

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.

RAJU’S WORKING-TRAY ANALOGY
01
Order book
Records saved outside the active task
02
Working tray
Selected information used now
03
Space for a reply
Generation budget when shared
The tray is only an analogy. A context window is measured in tokens, not physical slips or fixed numbers of messages.

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.

FICTIONAL 8,000-TOKEN BUDGET
01
Input: 6,000
500 + 2,000 + 3,500
02
Generation: up to 2,000
8,000 − 6,000
03
Total ceiling: 8,000
Input and generation together
These are invented counts for arithmetic practice. Real requests may include formatting, tool, multimodal, or reasoning overhead and separate output caps.
Maximum output is a ceiling, not a target.

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.

SAVED DOES NOT ALWAYS MEAN INCLUDED
01
Stored conversation
The app’s available history
02
Context preparation
Select, retrieve, or summarize
03
Model request
Only the material actually supplied
If a detail matters, restate it clearly or provide a concise current brief. Do not assume the model sees the whole chat.

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.

TWO DIFFERENT LIMIT PROBLEMS
01
Input/context too large
Reduce or select material; check budget
02
Output limit reached
Allow a suitable output budget or split the task
Do not assume every service automatically drops the oldest message or resumes an interrupted answer.

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.

MAKE THE CONTEXT USEFUL
01
Keep
Current menu and relevant question
02
Remove
Duplicates and unrelated history
03
Check
Did the response use the right facts?
Summaries save space but can lose details. Retrieval brings back selected material; it does not guarantee correctness.

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.

A PRACTICAL BACKEND CHECK
01
Before sending
Count or estimate complete input
02
Budget
Reserve output and relevant overhead
03
After receiving
Inspect usage and finish status
Avoid fixed “words per token” assumptions for code, mixed languages, or images and audio. Modality accounting varies by service.

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.

Practice prompt
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.

YOUR ONE-SENTENCE TAKEAWAY

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?


Sources and further reading

Limits and accounting vary by model and service. The 8,000-token budget is a fictional teaching example.

Comments

Popular posts from this blog

Beyond Standard RAG: The Architecture of Agentic Retrieval and Self-Correction Loops

The Architecture of Vision-Language Models: How Multimodal AI Sees and Understands the World

Java Collection Framework: A Practical Guide with Examples