Tokens and Context Windows
Learn what tokens are, how context windows limit a chatbot, and how to work with long documents and chats.
Key takeaways
- Tokens are words, pieces of words, punctuation or spaces, and different models split the same text differently.
- The context window covers input and output together, so a very long prompt leaves less room for the answer.
- When a conversation outgrows the window, apps trim, summarize or refuse, and details can silently disappear.
- Sending less irrelevant material usually gives better answers and lower costs.
A token is the small unit of text an AI language model reads and writes, and a context window is the maximum number of tokens it can take into account at once. Everything the model uses for a reply, including instructions, your earlier messages, attached files and the reply itself, has to fit in that window.
If a chatbot seems to forget the start of a long conversation, rejects a big document, or charges more for a long request, tokens and the context window are usually the reason.
What a token is
Models don't read letters or whole sentences directly. A component called a tokenizer breaks text into pieces drawn from a fixed vocabulary, and each piece has an ID number. Frequent words such as "the" or "network" are often a single token. A rarer word may be split into two or more parts, such as a stem and an ending.
Spaces, punctuation and line breaks count too. In many tokenizers the space before a word is part of that word's token. Numbers are frequently split into short groups of digits, and symbols or emoji can take several tokens each.
Exact splits depend on the tokenizer, so treat the picture above as an example. A rough rule for English is that a token averages somewhat less than one word, often estimated at around four characters. Other languages, especially those written in scripts that were less common in the tokenizer's training text, can take noticeably more tokens for the same meaning. Code also tends to use many tokens because of symbols and indentation.
Estimating the size of your text
You don't need exactness for most work. Paste text into a word and character counter and estimate tokens as somewhat more than the word count for ordinary English prose. For code, logs or non-Latin scripts, leave a wider margin.
If precision matters, for example when paying per token through an API, use the tokenizer or counting feature the provider offers for the specific model. Counts from one model's tokenizer don't carry over reliably to another.
Characters are also not as simple as they look. Emoji and accented letters can be encoded several ways, which affects both byte length and token count. The Unicode text inspector shows what's really in a string.
The context window
The context window is the model's working space for a single request. It's measured in tokens, and sizes vary widely: older or smaller models handle a few thousand, while many newer ones handle hundreds of thousands or more. Providers change these limits, so check the current documentation for whichever service you use.
Input and output share the budget, and many services set a separate cap on output length. A model with a large window might still produce only a fraction of that size in one reply, which is why a request to rewrite a whole book usually has to be done in sections.
What happens when you run out
The model itself can't process more than its window. The application around it decides what to do, and approaches differ:
- Refuse the request with an error saying the input is too long.
- Drop the oldest messages so newer ones fit.
- Summarize earlier turns into a shorter note that replaces them.
- Retrieve only relevant chunks of a large document instead of loading all of it.
- Cut the reply short when the output limit is reached.
Some of these are invisible. A chat that starts ignoring an instruction you gave at the beginning may have lost it to trimming. If a rule matters, restate it, or put it in whatever custom-instructions setting the app provides.
Why long context isn't free
Models have to process every token in the context for each reply. Longer inputs take more time and computing power, and per-token pricing on APIs means you pay for them. In a chat, the whole history is typically sent again on each turn, so costs grow as the conversation does. Some providers offer caching that lowers the price of repeated content.
Quality can also suffer. A model may attend unevenly to a very long input, and a relevant fact buried among thousands of irrelevant lines can be missed. A window large enough to hold something is no guarantee the model will use all of it well.
Energy follows computing. The energy cost of AI queries depends partly on how much text goes in and comes out.
Working with long documents
Say you have a long product manual and want to know how to reset one setting. Pasting the entire manual might work, but you'll often do better with a more targeted approach:
- Search the document yourself and paste only the relevant chapter.
- Include the heading and surrounding paragraphs so the model has context.
- State the question after the pasted text and say what you want back.
- Ask the model to quote the passage it relied on, then confirm the quote exists in the original.
For documents too big to fit, split them at natural boundaries such as chapters, summarize each, then work from the summaries and return to the original sections for details. Keep in mind that summaries lose information, and errors in them carry forward.
Retrieval as a workaround
Systems that handle large collections usually don't load everything. They break documents into chunks, index them, and fetch the few most relevant for each question. This is retrieval-augmented generation, described in retrieval-augmented generation in search.
Retrieval saves space and keeps answers tied to your material, but it can miss. If the search step picks the wrong chunk, the model answers from incomplete information, sometimes without saying so. Fine-tuning vs. retrieval compares this approach with retraining a model.
Tips for managing a long chat
Start a new conversation for a new topic. Leftover discussion about last week's printer problem only adds noise to today's spreadsheet question.
Before switching, ask the assistant to write a short summary of decisions, constraints and open items. Check it, correct anything wrong, and paste it into the new chat. This gives you a clean window with the important facts at the top.
Put the most important instructions where they're easy to find: clearly at the start or right alongside your question. Use headings or labels around pasted material, such as "Error log:" and "My question:", so the model can tell them apart. How to write better prompts has more on this.
Why tokens explain some odd mistakes
Because a model reads tokens, it doesn't naturally see the letters inside them. Questions about how many times a letter appears in a word, or about spelling backwards, can trip it up. Long arithmetic suffers for related reasons, since digits get grouped unevenly. Tools that run real code handle these reliably.
Tokenization also helps explain why prompts in different languages can behave differently in length, cost and sometimes quality. If you work in a language other than English, test with your own material, and don't assume the English estimates apply.
A worked budget example
Say a model has a window of 8,000 tokens, a made-up round number for illustration. Your app's instructions take 500. You paste a report of about 4,000 tokens and add a 100-token question. That leaves roughly 3,400 tokens for the reply and everything that follows.
If the answer runs to 1,000 tokens and you ask a follow-up, the next request has to carry the instructions, the report, your first question, that answer and the new question. About 2,300 tokens remain. Two or three more long exchanges and the app has to start dropping or compressing something.
The fix is rarely a bigger window alone. Paste only the section of the report you're asking about, request a short answer when a short one will do, and start over once you've moved to another part of the document. The same arithmetic applies with much larger windows. It simply takes longer to fill them, and each request carries more weight in time and cost along the way.
Developers building on an API should plan this explicitly: reserve space for the reply, count the inputs before sending, and decide what gets trimmed first. Leaving that decision to chance means finding out through an error, or through an answer that quietly ignored half the instructions.
Common questions
Is the context window the same as memory?
No. The window is what the model can see for the current request. A memory feature is a separate store that an app reads from and writes to, then inserts selected notes into the window. Once you remove a note or start fresh, the model doesn't retain it.
Does a bigger window mean a smarter model?
Not by itself. A large window lets you include more material, which helps for long documents and codebases. Reasoning quality, training and how well the model uses distant information are separate matters.
Can I see how many tokens I've used?
Developer APIs normally report input and output counts with each response. Consumer chat apps often hide them, though some warn you when a conversation is getting long.