Interactive · the real tokenizerType anything.
50 real examples — tap any card to load it into the box.
How it worksThe pipeline
A language model never sees letters — only integers. GPT-4o's tokenizer converts text in five stages: special tokens split first, a regex cuts the rest into pieces, each piece becomes raw UTF-8 bytes, and byte-pair encoding repeatedly merges the lowest-ranked adjacent pair. Merges never cross a regex boundary.
How it worksByte-pair encoding, watched
"token" starts as 5 raw bytes. Each step fuses the pair with the lowest merge rank — ranks learned from real text, so common letter pairs merge first. Four merges, one token (#15263). The algorithm never considers meaning, only frequency.
The best partThe possessive-quantifier detective story
OpenAI publishes the pre-tokenizer regex with possessive quantifiers (?+, *+, ++) — matchers that never give characters back. But tiktoken's core is Rust, and Rust's regex crate has no possessive quantifiers: it silently parses a++ as nested (a+)+, i.e. plain greedy. That changes real output:
Type a b (a, two spaces, b) into the playground and see for yourself: tiktoken gives a | space | space-b. A truly possessive regex would give a | double-space | b. The published pattern and the running code disagree — and the code wins. Footnote: tiktoken's own pure-Python encode_ordinary path uses the regex module, which does implement possessive — so tiktoken disagrees with itself depending on which door you enter through.
How it worksThe 7 regex branches
Before any merging, the regex decides the maximum span a token may cover:
How it worksVocabulary anatomy
The 256 byte tokens are the escape hatch: every byte is in the vocabulary, so every Unicode string has exactly one encoding — even text the tokenizer never saw in training.