The Secret Language of LLMs: Tokens, Tokenizers, and Context Windows
Large Language Models generate text by predicting what should come next.
For example:
The capital of India is ...
A model may continue with:
New Delhi
Then it repeats the process, generating one token after another until the response is complete.
From the outside, it can feel as if the model is simply reading words and writing more words.
But an LLM is built using a neural network, and that neural network does not work with written words in the same way humans do.
Inside the model, computation happens using numerical representations.
So before a sentence can be processed by the model, human-readable text must first be converted into a form that the neural network can work with mathematically.
That sounds simple, but it raises several questions.
If you type:
He is amazing.
does the model receive three words and a full stop?
To answer this questions, we first need to understand how text is broken into smaller pieces.
1. Text Does Not Go Directly Into the Model

Imagine this sentence:
He is amazing.
Before the model processes the text, it is represented as smaller units.
For teaching purposes, imagine the split looks like this:
He | is | amazing | .
These smaller units are called tokens.
A token is a unit of text produced by the model's tokenization scheme.
For intuition, think of it as:
a piece of text represented as one unit for model processing.
A token can represent:
a whole word,
part of a word,
punctuation,
a symbol,
a character,
or text together with surrounding whitespace.
So this common assumption is wrong:
One word = one token
For example:
programming
might be one token in one system.
Another system might split it into something like:
program | ming
The exact split depends on the tokenizer and its vocabulary.
The key idea is:
Word ≠ Token
2. What Is a Tokenizer?
Now that we know what tokens are, we can name the component that creates them.
A tokenizer is the component that turns text into tokens and maps those tokens to numerical IDs called token IDs.
Conceptually:
Text
↓
Tokenizer
↓
Tokens
↓
Token IDs
Suppose we start with:
I love programming
A tokenizer might conceptually split it into:
I | love | programming
Then each token is matched with an ID:
I → 51
love → 872
programming → 4381
So the model may receive something like:
[51, 872, 4381]
The values above are only illustrative. Real token IDs depend on the tokenizer being used.
Encoding and Decoding
Turning text into token IDs is commonly called encoding.
Readable Text
↓
Encoding
↓
Token IDs
Converting token IDs back into text is called decoding.
Token IDs
↓
Decoding
↓
Readable Text
So during generation, the broad flow is:
Text
↓
Tokens
↓
Token IDs
↓
Language Model
↓
Generated Token IDs
↓
Readable Text
This gives us the first useful mental model for how human-readable text reaches a language model.
3. Token IDs Do Not Contain Meaning
Suppose a tokenizer assigns Token ID:
Java → 932
React → 145
Apple → 71
Dog → 503
You might notice:
932 > 145
Does that mean Java has more meaning than React?
No.
A token ID is an identifier within a particular tokenizer vocabulary.
Think of employee IDs:
Rahul → 142
Anita → 781
The fact that:
781 > 142
does not make Anita more important than Rahul.
The number identifies the employee.
It does not describe the employee.
Token IDs work in the same way.
Java → 932
roughly means:
Use vocabulary entry 932.
It does not mean that the numerical value 932 itself contains the meaning of Java.
So remember:
Token ID ≠ Meaning
This distinction becomes extremely important later when we ask how a model represents relationships between concepts.
4. Why Not Use One Token for Every Word?
A simple idea would be to give every word its own token.
For example:
boy
girl
computer
programming
developer
Then:
This is a boy
could become:
This | is | a | boy
That looks convenient.
But consider:
develop
developer
developers
developing
development
developmental
Should every variation require a completely separate entry?
Now add:
names,
company names,
technical terms,
spelling variations,
URLs,
code identifiers,
new words,
and many human languages.
The vocabulary would become extremely large.
There is another problem too:
What happens when the system sees a word that is not already stored as a complete entry?
A pure word-level approach therefore creates serious vocabulary and coverage problems.
5. Why Not Use Individual Characters?
We could go to the other extreme.
Instead of:
programming
we could use:
p | r | o | g | r | a | m | m | i | n | g
Now unfamiliar text is easier to represent because it can be built from smaller units.
But sequences become much longer.
Longer sequences mean:
more positions for the model to process,
more context space used,
more computation,
and potentially higher API usage.
So we have two extremes:
Whole words
→ shorter sequences
→ very large vocabulary
and:
Characters
→ smaller vocabulary
→ very long sequences
A practical system needs something between them.
6. The Middle Ground: Subword Tokens
This leads to subword tokenization.
A subword is simply a reusable piece of text that can be smaller than a full word but larger than a single character.

Imagine:
untrustable
being split conceptually into:
un | trust | able
Now pieces can be reused:
unable
→ un | able
trustable
→ trust | able
untrusted
→ un | trust | ed
The exact splits above are only examples.
A real tokenizer may divide those words differently.
The important idea is the trade-off:
Characters ←──── Subwords ────→ Whole Words
↑
practical middle
Subword tokenization offers a practical trade-off: it can keep the vocabulary manageable without turning every word into a long sequence of tiny units.
Token Boundaries Are Not Meaning Boundaries
There is one important detail.
If you see:
un | trust | able
you may naturally interpret:
un = not
trust = trust
able = capable of
But a tokenizer does not need to split words according to grammar or human meaning.
Its job is to create units that work well for the tokenization scheme; those boundaries do not have to match human linguistic analysis.
So:
Token boundary ≠ Semantic boundary
A token can be useful to the model even if its boundary looks strange to Us.
7. How Does a Tokenizer Build Its Vocabulary?
A tokenizer works with a vocabulary: a mapping between token pieces and their token IDs.
Each vocabulary entry has a token ID.
For example:
Token | Token ID |
|---|---|
| 23232 |
| 43 |
| 718 |
| 13 |
So:
Java is good.
might become:
Java | is | good | .
and then:
[23232, 43, 718, 13]
But how are useful text pieces chosen?
There are several tokenization methods, including BPE, WordPiece, and Unigram.
One well-known approach is Byte Pair Encoding, usually shortened to BPE.
The name sounds complicated, but its core intuition is simple.
Imagine the text contains:
low
lower
lowest
For a simplified character-level illustration, start with small pieces:
l | o | w
l | o | w | e | r
l | o | w | e | s | t
If:
l + o
appears together often, those pieces can be merged:
lo
Later:
lo + w
might also become:
low
The simplified idea is:
Start with small pieces
↓
Find recurring neighboring pieces
↓
Merge useful patterns
↓
Repeat
↓
Build reusable vocabulary pieces
You do not need the full BPE algorithm to understand the important point:
A tokenizer can learn reusable text pieces from patterns in data instead of storing every possible word manually.
Real implementations include additional preprocessing details, and byte-level BPE begins from bytes rather than ordinary characters. But the merge intuition above is enough to understand the main trade-off.
BPE is not the only tokenization method; WordPiece and Unigram are other widely used subword approaches.
8. The Same Text Can Tokenize Differently
Token IDs only make sense relative to the tokenizer vocabulary that defines them.
If one tokenizer says:
Java → 23232
another tokenizer may:
assign Java another ID,
split it into multiple tokens,
or use a different vocabulary entirely.
Therefore:
Same Text
+
Different Tokenizer
=
Potentially Different Tokens
Consider:
Artificial intelligence is amazing.
chatgpt tokenizer might produce:
Artificial | intelligence | is | amazing | .
Another gemini tokenizer might produce:
Art | ificial | intelligence | is | amazing | .
That means the same sentence can have different token counts.
This matters because token count can affect:
API cost,
context usage,
how much room remains for output,
and processing requirements.
So:
100 words ≠ necessarily 100 tokens
and:
Different tokenizer ≠ same token count
Does a Larger Vocabulary Mean a Better Model?
No.
A larger vocabulary can represent some common text with fewer tokens, but it also has trade-offs.
Designers balance things such as:
vocabulary size,
sequence length,
language coverage,
memory,
and compute.
So:
Larger vocabulary ≠ Better model
Tokenization is one part of the system, not a measure of intelligence.
9. Languages, Emojis, and Code
Tokenization is especially important outside simple English text.
Different Languages
Consider:
I am learning English.
and:
मैं अंग्रेज़ी सीख रहा हूँ।
They can communicate similar ideas but still use different numbers of tokens.
Why?
Because a tokenizer's vocabulary and encoding rules may represent patterns from different languages differently.
So:
Same meaning does not mean same token count.
Emojis
Consider:
😂
or:
👨👩👧👦
What looks like one visual symbol to us is not guaranteed to be one token.
Unicode representation and the tokenizer's vocabulary can cause a visible emoji to be represented by one or several tokens.
So:
One visible symbol ≠ necessarily one token
10. What Is a Context Window?
So far, we have looked at how normal text becomes tokens and token IDs.
But when you chat with an AI assistant, the model usually receives more than just your current message.
For example, the application may give the model:
Instructions
+
Previous Messages
+
Your Current Message
+
Rules
+
Retrieved Information / Tool Results
Your current message is only one part of the complete input.
The exact information included depends on the application.
The important idea is:
The model can receive instructions, previous conversation, your current message, retrieved information, and tool results together.
All of this becomes part of the information available to the model for the current request.
But the model cannot consider an unlimited amount of information at once.
There is a limit to how many tokens can be included in a single request.
That limit is called the context window.
You can think of the context window as:
the maximum amount of tokenized information the model can work with at one time.
Conceptually:

Context Window
Instructions
+
Previous Messages
+
Current Message
+
Retrieved Information
+
Tool Results
+
Generated Response
As more information is included, more of the available context capacity is used.
The response generated by the model also uses tokens.
The exact limits and accounting differ between models, but the important rule is:
The context window has finite capacity.
This means a conversation cannot keep growing forever while every previous message remains fully available to the model.
And that leads to another important distinction:
What you can see in the chat history is not necessarily the same as what is currently included in the model's context.
12. Context Window Is Not Permanent Memory
Suppose a chat contains hundreds of messages.
You may still be able to scroll back and see the first message.
That does not mean every old message is sent to the model again with every new request.
An application may:
send some previous messages,
remove irrelevant ones,
summarize older conversation,
retrieve relevant information when needed,
use a separate memory system,
or combine these approaches.
Therefore:
Visible Chat History ≠ Exact Active Context
and:
Context Window ≠ Permanent Memory
A useful analogy is a desk.
You may own thousands of books, but only some can be open on your desk at one moment.
The context window is closer to that desk than to the entire library.
13. More Context Is Not Automatically Better
A large context window tells us how much tokenized information a model can accept within its limits.
It does not guarantee that every piece of that information will be used equally well.
So:
Context Capacity
≠
Perfect Context Utilization
This is an important engineering distinction.
Imagine you are debugging one error.
You could send:
600 source files
+
all logs
+
the full database schema
+
months of conversations
+
all documentation
That gives the model more information.
But the useful evidence may be buried inside noise.
A better request might contain:
Relevant Component
+
API Response
+
Stack Trace
+
Expected Behavior
So the goal is not:
send as much information as possible.
The better goal is:
send the information that is actually useful for the current task.
This broader design problem is often described as context engineering.
Context engineering means deciding what information the model should receive, how that information should be represented, and when it should be supplied.
14. Why Retrieval Helps
Suppose your system contains:
100,000 documents
Putting all of them into the model context would usually be wasteful or impossible.
Instead, the application can first find the most relevant parts:
Question
↓
Search Documents
↓
Retrieve Relevant Sections
↓
Send Those Sections to the Model
Finding relevant information from an external source is called retrieval.
When a system retrieves relevant information and supplies it to a model as context for generation, the pattern is commonly called Retrieval-Augmented Generation, or RAG.
The important idea is simple:
Find useful information first. Give the model only what it needs.
This helps control:
context usage,
noise,
cost,
and relevance.
15. Longer Prompt Does Not Mean Better Prompt
More tokens do not automatically create a better answer.
Compare:
Too Vague
Explain closures.
Short, but unclear.
Long but Noisy
I would like you to explain the JavaScript concept called
closures and explain closures in JavaScript and describe
the closure concept...
Longer, but repetitive.
Clear and Specific
Explain JavaScript closures to a beginner who understands
functions and scope.
Use one practical example and explain why an inner function
can still access an outer variable after the outer function returns.
This is longer than the first prompt, but almost every sentence adds useful information.
A good prompt gives the model:
the task,
relevant context,
the expected level,
useful constraints,
and the desired output.
So:
Better prompt ≠ Longer prompt
The goal is useful context, not maximum token count.
16. Why Tokens Matter in Real Systems
Tokens are not just an internal language-model detail.
They affect practical system design.
Token count can influence:
API cost,
context limits,
available output space,
document chunking,
retrieval design,
multilingual usage,
code processing,
and the amount of computation required.
Do not estimate exact token counts by counting words.
For example:
10,000 words
does not mean:
10,000 tokens
Token count depends on:
the tokenizer,
language,
punctuation,
spaces,
code,
names,
symbols,
and formatting.
Rough estimates can be useful, but when exact limits or costs matter, use the tokenizer or token-counting mechanism for the model you are actually using.
17. Common Misconceptions
Misconception | Better Mental Model |
|---|---|
One token = one word | A word may become one or several tokens |
Every model uses the same tokenizer | Different models can use different tokenization systems |
Token IDs contain meaning | IDs identify vocabulary entries |
Token boundaries follow grammar | Token boundaries do not have to match human linguistic boundaries |
One emoji = one token | A visible symbol may require multiple tokens |
Larger vocabulary = better model | Vocabulary design involves trade-offs |
Large context = perfect memory | Capacity does not guarantee perfect use |
Visible history = active context | Applications may summarize, retrieve, or omit information |
More tokens = better answer | Relevant context matters more than raw length |
18. Putting Everything Together
Now we can follow one sentence through the whole process.
You type:
He is amazing.
The application prepares the model input.
Then:
Human-Readable Text
↓
Tokenizer
↓
Tokens
↓
Token IDs
Conceptually:
He | is | amazing | .
might map to:
[1544, 382, 8467, 13]
Those IDs become part of the model's active context.
The context may also include:
instructions,
earlier messages,
retrieved information,
and tool results.
The language model processes its numerical representations and produces a prediction for the next token.
That new token becomes part of the sequence, and generation continues token by token.
The generated token IDs are decoded into text that can be shown to the user.
So the complete mental model is:
Application Input
↓
Structured Text
↓
Tokenizer
↓
Tokens
↓
Token IDs
↓
Finite Context Window
↓
Language Model
↓
Generated Token IDs
↓
Decoding
↓
Readable Response

Final Takeaway
We started with a simple question:
How does the text we write become something a language model can process?
Now we can follow the path:
Human Text
↓
Tokenizer
↓
Tokens
↓
Token IDs
↓
Language Model
Along the way, we learned that:
a token is not always a complete word,
different tokenizers can split the same text differently,
token IDs are only identifiers,
subword tokenization helps balance vocabulary size and sequence length,
all the information given to the model must fit within a limited context window,
and more context does not automatically mean better context.
But we have only solved one part of the problem:
how text reaches the model.
There is still something important missing.
Suppose:
Java → 23232
Python → 9821
Banana → 417
These numbers only identify vocabulary entries.
They do not explain why:
Java ↔ Python
should be treated as more closely related than:
Java ↔ Banana
So the next question becomes:
How does the model turn these simple IDs into numerical representations that can capture useful relationships between concepts?
That is what we will explore in the next chapter.