What is a token?
When you type a message to a chatbot, you see words. The chatbot does not. Before it does anything, a simple program chops your message into small pieces called tokens. A token is a chunk of text the chatbot treats as one unit.
A token can be a whole word like cat. It can be just part of a word, like un in "unhappy". It can also be a space or a punctuation mark. The chunks are not always what you would pick, but they are always the same for the same text.
Why not just use letters or words?
Think of a box of LEGO. You could build with tiny single studs (letters), or only with giant pre-built walls (words). Neither is great.
- Only letters: every message becomes very long, and a chatbot has to put in extra work to figure out that c-a-t means a furry animal.
- Only whole words: you need a piece for every word ever invented, plus every typo, name, and new slang word. Any word not on the list breaks the system.
- Chunks in the middle: common words get one piece, and rare words get built from a few pieces. Short messages, and nothing is ever unreadable.
That middle choice is what tokens are. The full list of pieces a chatbot knows is called its vocabulary. Real chatbot vocabularies are big, often on the order of tens of thousands to hundreds of thousands of pieces.
Remember this: a token is not the same as a word. Short, common words are usually one token. Long or unusual words get split into several.
How does text get split into tokens?
The program that does the chopping is called a tokenizer. Type anything below and watch it split live. This tokenizer uses one simple rule, greedy longest match: at each spot, grab the longest piece from the vocabulary that fits, then move on.
This is a toy. It only knows about 300 pieces. Real chatbots have vocabularies of around 100,000 pieces, so they split text into fewer, bigger chunks. Gray striped chips are characters the toy does not know, so it falls back to one chip per character. A dot inside a chip stands for a space.
Try a few things. Type a made-up word like "flibbertigibbet". Type a sentence with a typo. Notice how short, common words become one chip while odd words shatter into many.
How do tokens become numbers?
Computers only do math, and math needs numbers. So every token in the vocabulary has an ID number, like a locker number. Look at the small number under each chip above. That is its ID.
What you typed
What the model receives
The IDs in this toy are made up, and in a real chatbot they are different. The idea is the same: the chatbot never sees the letters. It sees a list of numbers. Next, it turns each ID into a longer list of numbers that captures what the token means, which is the story of From Words to Vectors.
What is a context window?
A chatbot cannot look at an unlimited amount of text. It has a cap on how many tokens it can handle at one time. That cap is called the context window. Think of it as the chatbot's desk: only the papers that fit on the desk can be used.
Everything counts toward the limit: your messages, the chatbot's replies, and any instructions it was given. When a chat grows past the limit, the oldest tokens fall off the desk. The chatbot does not choose to forget. They simply no longer fit.
The chat starts with "My name is Sam." Keep chatting until the bar is full. Then ask the chatbot your name. Token counts here come from the toy tokenizer above, and the window is far smaller than a real one. Real context windows hold thousands of tokens or more, and the size depends on the chatbot.
A bigger window lets a chatbot keep more of a long chat in view, but it is never infinite. If a chatbot seems to forget something you said a long time ago, this is often why. Repeating the key fact fixes it.
Why do tokens affect cost, speed, and letter counting?
Cost
Chatbots do their math on tokens, so tokens are what they count. Many AI services measure usage, and set prices, by the number of tokens going in and coming out. A longer message means more tokens, which means more computing work.
Speed
A chatbot writes its answer one token at a time. Each new token needs another round of math. That is why a long answer takes longer to appear than a short one, and why you see text show up piece by piece.
Why chatbots miscount letters
You have probably seen a chatbot get "How many r's are in strawberry?" wrong. Here is why. To the chatbot, the word is not a row of letters. It is one or two chunks, each a single ID number.
You see letters
It sees chunks
Counting the r's means looking inside each chip. But the chatbot only has the chip's ID number. The letters are sealed in the box.
The chatbot has learned a lot about spelling from text, so it often gets counts right. When it gets one wrong, it is making a pattern-based guess rather than counting. The fix is simple: ask it to spell the word out letter by letter first, then count. Spelling puts each letter in its own token.
How does a chatbot predict the next token?
Here is the chatbot's one trick. Given all the tokens so far, it scores every token in its vocabulary by how likely it is to come next. Then it picks one, adds it to the text, and does the whole thing again. Every answer is built this way, one token at a time.
It does not always pick the top choice. If it did, it would give the same answer every time. Picking among the likely options with some chance is part of why a chatbot can answer the same question differently twice. You can read much more in How Do LLMs Answer Questions? and What Is an LLM?
Pick the token you think a chatbot finds most likely.
The percentages are made up to show the idea. A real model computes its own scores for its whole vocabulary, not just four choices.
The bar under each choice shows how likely the toy model thinks it is. Even the unlikely tokens have some chance. That is also how chatbots can say surprising or wrong things: a less likely token gets picked, and every token after it builds on that.
Quick quiz
1. What is a token?
2. A chat goes on for a very long time, and the chatbot forgets your first message. What is the most likely reason?
3. Why might a chatbot miscount the letters in a word?
KEY TAKEAWAYS
- Chatbots read tokens: chunks of text, not letters or whole words.
- Splitting into chunks keeps messages short and lets the chatbot handle any word, even new ones.
- Each token has an ID number. The chatbot works with numbers, not letters.
- The context window is the limit on how many tokens a chatbot can use at once. The oldest fall out first.
- More tokens means more cost and more time. Letters hidden in tokens are why counting them is hard.
- A chatbot writes one token at a time by predicting what is likely to come next.
Questions people ask about tokens
What is a token in AI?
A token is a small chunk of text that a chatbot reads as one unit. It can be a whole word, part of a word, a space, or a punctuation mark. The chatbot turns each token into a number before it does any math.
How many words is a token?
It depends on the text and the chatbot. In English, a token is often a little less than one word, so a page of text has somewhat more tokens than words. Short common words are usually one token. Long or rare words are split into several.
What is a context window?
A context window is the limit on how many tokens a chatbot can look at at one time. Your messages and its replies all count. When a chat gets too long, the oldest parts no longer fit and the chatbot can't use them.
Why can't chatbots count the letters in a word?
A chatbot sees a word as one or a few tokens, not as a row of letters. To count the letter r in strawberry it has to guess from patterns it learned, because the letters are hidden inside the chunks. That is why it sometimes gets simple counts wrong.
Keep learning how AI works
Now you know how a chatbot reads. Next, see how those token IDs turn into meaning in From Words to Vectors, how a model puts an answer together in How Do LLMs Answer Questions?, or start with the big picture in What Is an LLM? Want to go deeper? CodeHS has AI Literacy and Cybersecurity courses in the course catalog.