Lesson 2 of 26 in AI Enablement: LLMs in Practice · 12m
Tokens and context windows
When you use an LLM through an API or a business plan, you will see two numbers again and again: tokens and the context window. They decide how much you can send, how much you pay and how much the model can keep in mind at once. Understanding them saves money and explains a lot of puzzling behaviour.
What a token is
Models do not read letters or whole words. Before text reaches the model, a tokenizer splits it into tokens: common chunks of characters learned from training data. Frequent words are usually a single token ("the", "meeting"). Rarer words are split into pieces, so a word like "unbelievably" might become three tokens, such as "un", "believ" and "ably". Spaces and punctuation are usually attached to tokens too.
A few practical consequences:
-
Token counts are not word counts. For typical English prose, a common rule of thumb is about four characters, or roughly three quarters of a word, per token. So 1,000 tokens is roughly 750 words. Treat this as a rough estimate only.
-
Other languages and formats often cost more. Many tokenizers are trained mostly on English, so text in other languages, especially those with non-Latin scripts, frequently needs more tokens for the same meaning. Code, tables, long numbers and unusual formatting also tend to be token-heavy.
-
Each model family has its own tokenizer. The same text can be a different number of tokens in different models. Providers publish tokenizer tools or count tokens for you in their APIs.
Tokens also explain some odd failures. If you ask a model to count the letters in a word or reverse a string, it may stumble, because it never "sees" individual letters, only tokens.
Why token counts matter
Cost. Hosted models are usually priced per token, often with separate prices for input tokens (what you send) and output tokens (what the model writes), and output is typically more expensive. A prompt that pastes in a 40-page report every time can cost far more than one that sends only the relevant pages.
Speed. Output is generated one token at a time, so long answers take longer. Very long inputs also add processing time before the first word appears.
Limits. Every model has a maximum context size and usually a maximum output length. Hit either and the request fails or the answer is cut off mid-sentence.
The context window: the model's working memory
The context window is the total number of tokens a model can take into account in one request. It includes everything: the system instructions set by the product, the conversation so far, any documents you pasted, results from tools, and the answer being written.
A helpful analogy is a desk. The model's training is everything it learned over years of reading. The context window is the desk in front of it right now. It can only work with the papers currently on the desk. Context windows have grown dramatically, from a few thousand tokens in early chat models to hundreds of thousands or more in many current ones, but the desk is never infinite.
What happens as you approach or exceed the limit depends on the product:
-
The request is rejected with an error saying the input is too long (common in APIs).
-
Older messages are silently dropped or summarised to make room (common in chat apps). This is why a long conversation can "forget" instructions you gave at the start.
-
The answer is truncated because there is no room left for output.
Even within the limit, more is not always better. Models can pay less attention to material buried in the middle of a very long input, and irrelevant text can distract them. A focused 3,000-token prompt often beats a 100,000-token dump.
Practical tips for working within limits
-
Send what is relevant, not everything. Paste the three sections that matter rather than the whole handbook. Later in the course you will learn retrieval, which automates this.
-
Summarise in stages. For a document that does not fit, summarise each part separately, then summarise the summaries. Keep key numbers and names explicit in each stage.
-
Put instructions where they will be seen. Clear instructions at the start, and a short reminder of the task after a long document, help the model stay on track.
-
Ask for concise output. Specify length ("under 150 words", "five bullets"). It saves output tokens and usually improves quality.
-
Reset long conversations. When a task changes, start a new chat with a short summary of what matters.
-
Watch the bill on repeated calls. In automated workflows, the same large prompt may be sent thousands of times. Trimming it can cut costs substantially, and some providers offer prompt caching for repeated prefixes.
Key takeaways
- Models read and write tokens, chunks of characters; a rough English rule of thumb is about 4 characters or 0.75 words per token.
- Other languages, code and numbers often use more tokens, and each model family counts differently.
- Tokens drive cost, speed and limits; output tokens are usually priced higher than input tokens.
- The context window holds everything the model can see in one request, including its own answer.
- Send focused context, summarise in stages, ask for concise output and restart long chats.
This lesson also has interactive exercises. Open the course to try them and track your progress.