AI GLOSSARY · AI CONCEPTS
Byte-pair encoding (BPE)
Definition
Byte-pair encoding (BPE) is a method for building a subword vocabulary: start from single characters or bytes, then repeatedly merge the most frequent adjacent pair into one new unit until the vocabulary reaches a target size.
Also called: BPE, byte pair encoding, byte-level BPE.
In plain language
Byte-pair encoding is a way of deciding how to chop text into pieces before a language model reads it. Common words tend to end up as one piece, while rare words are split into smaller parts the model has seen before, so it can still handle a name or word it did not see in training. A rough comparison is a set of letter tiles where frequent combinations get their own single tile. The catch is that the pieces follow the training text, not meaning, so the same sentence can cost a different number of tokens in different models or languages. That matters when you budget a context window or estimate cost.
Technical definition
BPE was applied to subword segmentation in neural machine translation by Sennrich, Haddow and Birch (arXiv 1508.07909), who describe it as a compression-based technique that lets a fixed vocabulary represent rare and unknown words as sequences of subword units. The Hugging Face documentation describes the training procedure: a pre-tokenizer splits text into words and counts them, a base vocabulary is made from the characters, and BPE iteratively merges the most frequent adjacent pair, adding each merge to the vocabulary until the target size is reached. Byte-level BPE uses the 256 byte values as the base vocabulary, so any text can be tokenized without an unknown token; the documentation says GPT-2 uses it. The documentation also describes BPE as deterministic, based on merge rules.
Worked examples in this catalogue
Catalogue examples point at a skill, guide or coding tool listed on this site, with what to run and what you see. An example marked illustrative describes the item from its own documentation; it was not executed for this page. Platform Scores are our assessment under a published method, not a safety guarantee.
Guide · Illustrative, not executed
What Is an LLM? The Facts Agent Users Need
- What you see
- A guide to how an LLM reads and predicts tokens, with a note that the same text produces different token counts on different models.
- Why it exercises the concept
- BPE is one common way a tokenizer's vocabulary is built. The guide shows the practical effect: token counts, and so cost and context use, depend on the tokenizer.
Skill by Skill Almanac · Illustrative, not executed
context-window-packer 56/100 · Provisional, not yet measuredScored · Method v0.2 · How we score
- What you see
- Chooses which files fit one prompt's token budget and records what was kept, shrunk or dropped, and why.
- Why it exercises the concept
- Fitting a token budget needs a token count, and that count comes from the model's tokenizer. The skill is an adjacent use, not a BPE implementation.
Skill by Skill Almanac · Illustrative, not executed
agent-session-cost-review 58/100 · Provisional, not yet measuredScored · Method v0.2 · How we score
- What you see
- Finds where a coding-agent session spent its tokens, by parsing the saved session transcript.
- Why it exercises the concept
- Tokens are the unit a BPE vocabulary produces and the unit costs are measured in, so a per-session token breakdown is where its effect shows up.
How it shows up when you use agents
You do not usually see BPE directly. It shows up as the unit your agent is billed and limited in. When Claude Code, Codex or Cursor reports tokens used, those tokens are pieces from a tokenizer's vocabulary, and for many models that vocabulary was built with BPE or a close relative. The tokenizer page covers the whole component; this page covers one algorithm inside it.
Practical consequences. The same file can be a different number of tokens in a different model, because each model family has its own vocabulary. Code, non-English text and unusual identifiers can split into more pieces than plain English prose, so a count made by dividing characters by a fixed number can be off. Odd model behaviour on spelling or character counting can come from the model seeing pieces, not letters.
What breaks when this is misunderstood: people budget a context window by word count, or reuse a token count from one model for another, and then hit limits or get surprise costs. Next action: measure with the tokenizer or token-counting tool of the model you will actually run, and read the usage report after a run.
Common confusions
- BPE versus tokenizer. BPE is one algorithm for learning a vocabulary. A tokenizer is the full component that applies a vocabulary to text. Hugging Face lists BPE, Unigram and WordPiece as three subword algorithms.
- BPE versus WordPiece. Both merge pairs from the bottom up. Per the Hugging Face documentation, BPE merges the most frequent pair, while WordPiece merges pairs that maximize the likelihood of the training data.
- Byte-level versus character-based BPE. Byte-level BPE starts from 256 byte values, so any text can be represented. A character-based base vocabulary maps characters outside it to an unknown token.
- Myth: a token is a word. A token is a piece from the vocabulary. Common words stay intact as single tokens, and rare words are split into several.
Related terms
Terms that mention Byte-pair encoding (BPE)
2 terms mention this one
More in AI concepts
Sources
- Neural Machine Translation of Rare Words with Subword Units, arXiv (Sennrich, Haddow and Birch) (accessed 2026-11-24)
- Tokenization algorithms, Hugging Face (Transformers docs) (accessed 2026-11-24)
Definitions are written by Skill Almanac from these sources and were checked against them on 2026-11-25. Wikipedia is never the only source.
Review record
Last verified
Drafted by claude-sonnet-5-5; sources and example targets checked by Independent automated source review (OpenAI Codex); not human peer review on 2026-11-25. Last verified .
Change log (4)
- : Independent automated factual/example review completed. Cached US query estimate aligned to receipt; no traffic promise. Final technical gate recorded separately; publication disabled.
- : First version.
- : Verifier pass: applied verifier corrections to wording, aliases and claims.
- : Automated review completed; approved for the staged public release. Search indexing is controlled by the release configuration.