Andrej Karpathy on Tokenization
Karpathy sees tokenization as a necessary but flawed interface between text and language models that explains much of their strange behavior and deserves far more attention than most people give it.
- Tokenization turns raw text into the discrete units an LLM actually sees and predicts.
- Many apparent model failures are really tokenization failures, especially on spelling and string manipulation.
- Token efficiency matters in practice because tokens drive context use, cost, and usable prompt length.
- Karpathy dislikes tokenization as a design layer, but he thinks understanding it is essential because it has many sharp edges.
- He favors practical, efficient byte-level BPE tooling while hoping future systems can remove tokenization altogether.

“More efficient in tokens. Um, so for example, these are the same in JSON and in YAML. The JSON is 116 and the YAML is 99, so quite a bit of an improvement. And so in the token economy, where we are paying per token in many ways, and you are paying in the context length, and you're paying in, um, dollar amount for the cost of processing all this kind of structured data, when you have to, um, so prefer to use the YAML over JSON. And in general, kind of like, the tokenization density is something that you have to, um, sort of care about and worry about at all times and try to find efficient encoding schemes, and spend a lot of time in the tokenizer, and measure the different token efficiencies of different formats and settings and so on.”Talk / tutorial presentation, 2019 · 2:09:36
Tokenization is the gateway between text and the model
Karpathy treats tokenization as the step that converts human text into the sequence the model can actually process. The model does not work directly on words or meaning first; it works on token sequences, and the neural network operates over those representations token by token.1
That makes tokenization more than preprocessing. It shapes the basic objects the model predicts, which means it influences what patterns are easy or hard for the system to learn.1
A lot of weird LLM behavior starts at token boundaries
Karpathy's core warning is that many problems people blame on the model are actually caused upstream by the tokenizer. He says tokenization sits behind a lot of the weirdness people notice in language models, and he specifically points to spelling, simple string processing, and non-English text as areas where it bites.1
This is why models can seem smart in broad language tasks yet brittle on operations that look simple to humans. If the relevant pieces of text are split into awkward token chunks, the model is no longer reasoning over the clean units people imagine.1
Tokenization affects cost, context, and prompt design
Karpathy also connects tokenization to everyday use. Tokens are the scarce resource inside the context window, so the way text gets tokenized affects how much useful information you can fit, how much you pay, and how efficiently the model can work with your prompt.45
He gives a concrete practical implication: structured formats can differ in token efficiency, and that difference matters. His example is that YAML can be more efficient than JSON, so choosing representations with better token density can improve both cost and available context budget.6
That is why he advises being intentional about formatting and not stuffing a chat with irrelevant text. In his framing, prompt quality is partly a token-allocation problem.457

“More efficient in tokens. Um, so for example, these are the same in JSON and in YAML. The JSON is 116 and the YAML is 99, so quite a bit of an improvement. And so in the token economy, where we are paying per token in many ways, and you are paying in the context length, and you're paying in, um, dollar amount for the cost of processing all this kind of structured data, when you have to, um, so prefer to use the YAML over JSON. And in general, kind of like, the tokenization density is something that you have to, um, sort of care about and worry about at all times and try to find efficient encoding schemes, and spend a lot of time in the tokenizer, and measure the different token efficiencies of different formats and settings and so on.”Talk / tutorial presentation, 2019 · full transcript →
He dislikes tokenization, but he does not think you can ignore it
Karpathy is unusually blunt about his dislike of this layer. He calls tokenization his least favorite part of working with large language models and argues that anyone who can remove it would deserve enormous credit.89
But his attitude is not that tokenization is unimportant. It is the opposite: he thinks it is irritating precisely because it is full of sharp edges, including reliability, security, and safety issues, and therefore deserves serious attention.
So his position is two-part: tokenization is a bad abstraction in many ways, and understanding it is still mandatory if you want to understand model behavior.8
His practical preference is efficient byte-level BPE
When Karpathy turns from critique to implementation, he leans toward practical byte-level BPE approaches. He says he likes the byte-level BPE used by OpenAI and recommends efficient tooling for inference, while being more skeptical of alternatives with many settings and more ways to go wrong.
That preference fits his broader view of tokenization as an engineering compromise. Since this layer is unavoidable in current systems, he wants tokenizers that are efficient, predictable, and less likely to introduce hidden mistakes.
Karpathy on tokenization, in his own words
“…tokenization is my least favorite part of working with large language models…”
“More efficient in tokens. Um, so for example, these are the same in JSON and in YAML. The JSON is 116 and the YAML is 99, so quite a bit of an improvement. And so in the token economy, where we are paying per token in many ways, and you are paying in the context length, and you're paying in, um, dollar amount for the cost of processing all this kind of structured data, when you have to, um, so prefer to use the YAML over JSON. And in general, kind of like, the tokenization density is something that you have to, um, sort of care about and worry about at all times and try to find efficient encoding schemes, and spend a lot of time in the tokenizer, and measure the different token efficiencies of different formats and settings and so on.”
Where to watch
Andrej Karpathy on Tokenization: Building GPT's Tokenizer2019 · 134 min · full transcriptBest single source on Karpathy's view that tokenization explains many odd LLM failures and why byte-level BPE matters.
Andrej Karpathy on Using LLMs: Tools, Models, and Workflows2023 · 131 min · full transcriptShows how tokenization matters in practice through context windows, cost, and prompt formatting choices.
Andrej Karpathy on GPT From Scratch: How ChatGPT Works2022 · 116 min · full transcriptUseful for seeing the simpler idea underneath: text must be mapped into discrete tokens before the Transformer can model it.
Andrej Karpathy on Large Language Models: How ChatGPT Works2022 · 211 min · full transcriptGood high-level overview of LLMs where token prediction is framed as the core operation.
Questions people ask
- How does Andrej Karpathy decide when to use reasoning models, search, or tools with LLMs?
- What did Andrej Karpathy say about why tokenization causes strange LLM behavior?
- What tokenizers did Andrej Karpathy recommend using?
- What did Andrej Karpathy say about JSON versus YAML token efficiency?
- What did Andrej Karpathy say about the risks of tokenization?
Sources
Every quote above, word for word from the transcripts. Numbers match the text.
“A lot of the issues that may look like just issues with the neural network architecture or the large language model itself are actually issues with the tokenization…”
“…think of the tokens in the context window as a precious resource…”
“…don't overload it with irrelevant information…”
“More efficient in tokens. Um, so for example, these are the same in JSON and in YAML. The JSON is 116 and the YAML is 99, so quite a bit of an improvement. And so in the token economy, where we are paying per token in many ways, and you are paying in the context length, and you're paying in, um, dollar amount for the cost of processing all this kind of structured data, when you have to, um, so prefer to use the YAML over JSON. And in general, kind of like, the tokenization density is something that you have to, um, sort of care about and worry about at all times and try to find efficient encoding schemes, and spend a lot of time in the tokenizer, and measure the different token efficiencies of different formats and settings and so on.”
“…if it is the case that those tokens are not any more useful to your next query, I encourage you to do this…”
“…tokenization is my least favorite part of working with large language models…”
“…eternal glory goes to anyone who can get rid of it…”
How this guide was made: drafted with AI from the full transcripts of the recordings cited, then checked: every quotation must match a transcript word for word and be the speaker's own words, and an independent review gates accuracy. Methodology and corrections.

