Tokens and Context Windows: How LLMs Read Text
You have spent an hour planning a holiday with a chatbot: dates, a budget, a long list of hotels and train times. Then you ask it to remind you of the budget you gave at the very start, and it gets the number wrong. Nothing is broken. You have run into tokens and context windows, the two ideas that decide how much text a large language model can see at once.
What a token is
A token is a piece of text that the model treats as a single unit. It can be a whole word such as "time", part of a word such as "ably", a punctuation mark, or a word with the space in front of it. The program that does the cutting is called a tokenizer.
The neural network inside an LLM works only with numbers, so each token is then swapped for its ID, a number from the model's fixed list of known pieces, called its vocabulary. As you saw in What Is an LLM?, the model reads tokens and writes its answer one token at a time.
A handy rule of thumb for English: one token is about 4 characters, or about three quarters of a word. So 100 tokens is roughly 75 words, and a 1,000-word article is roughly 1,300 tokens. Treat these as estimates; the real count depends on the tokenizer and the text.
Look at the dots in the diagram. Most tokens carry the space that comes before them, so " arrived" with its space is a different token from "arrived" at the start of a line. This is one reason token counts rarely match word counts.
Why pieces, not letters or whole words
Why not just use letters? Then every word would become many tokens, texts would become very long, and the model would need far more work to connect the meaning spread across them.
Why not whole words? The vocabulary would need millions of entries and would still fail on new words, names and typos such as "tiffinwala" or "sooooo good".
Pieces sit in the middle. Before training, the tokenizer is built by scanning lots of text and repeatedly merging the most common pair of neighbouring pieces into one new piece, starting from single characters. A common version of this method is called byte-pair encoding (BPE). Frequent words end up as a single token, and rare words are split into familiar pieces. Because it can always fall back to single characters, or even raw bytes, any text at all can be written in tokens, even an emoji or a word nobody has typed before.
The context window: the size of the whiteboard
The context window is the maximum number of tokens a model can handle in one request. It covers everything together: hidden instructions the app adds (often called the system prompt), the earlier chat, any document you paste, your new question, and the answer the model writes.
The answer is included because of the loop from the previous lesson: each new token is added to the text, and the model reads the whole lot again to choose the next one. So whatever you send must leave room for the reply.
Window sizes vary a lot. Early chat models handled a few thousand tokens. Many current models handle hundreds of thousands, and some a million or more; a million tokens is several long novels' worth of English. A bigger window is not perfect attention, though: models can still miss a detail buried in the middle of a very long input.
What happens when the board fills up
The model keeps no memory between requests. Each time you send a message, the app sends the whole conversation again, as tokens, along with your new question. That works until the conversation is bigger than the window.
At that point the app has to choose. It can drop the oldest messages, replace them with a short summary, or ask you to start a new chat. Whatever it does, the model cannot see text that is no longer on the board, so it seems to forget how the chat began.
In a long task, restate the facts that matter ("Reminder: the budget is ₹40,000"), or start a fresh chat and paste a short summary of what was decided. Both put the important facts back on the board.
Why tokens matter: cost, speed and language
Cost. Models offered by companies over the internet are usually priced per million tokens, with one price for input (what you send) and another for output (what the model writes). Output usually costs more. Free chat apps hide this, but they still limit how much you can use.
Speed. The answer is produced one token at a time, so a 600-token answer takes longer than a 60-token one. A very long input also takes longer to process before the first word appears.
Language. Tokenizers are usually built from text that is mostly English, so English words are often a single token. Other languages, such as Hindi or Tamil, and code full of symbols often split into more pieces for the same meaning. The same message then costs more, runs slower and fills the window faster. Newer tokenizers have narrowed this gap, but it has not disappeared.
Check yourself
Roughly how many tokens is a 300-word English email?
About 400, because a token is roughly three quarters of an English word; the exact count depends on the tokenizer.
Why does the model's own answer count against the context window?
Each token it writes is added to the text it reads for the next step, so the reply must fit in the same window as the input.
A chatbot forgets a detail from the start of a very long chat. What most likely happened?
The chat outgrew the window, so the app dropped or summarised the oldest turns and the model can no longer see them.