Zero Labs
Industry News / AI

Tokens: The Atom of Everything in Large Language Models

Source · Towards AI By Vansh Sharma

From the publisher’s feed, collected in the ZeroLabs newsroom.

Series: An Engineer’s Explorations in LLM Concepts“It started with a simple question: What exactly is a token? Three hours later, I had filled six browser tabs, youtube videos and had somehow ended up reading about some 5–6 concepts of LLM.”If you’ve worked with any LLM API — OpenAI, Anthropic, Gemini — you’ve seen the word token everywhere. In the docs, in the pricing, in the error messages. And at some point you’ve probably thought: okay but what actually is a token?The Simple Answer (Plain English First)Think of a token as a chunk of text — not necessarily a full word, not a single character, but something in between.The sentence:"I love tokenization"…doesn’t become 3 tokens (one per word). It becomes something like:["I", " love", " token", "ization"]Four tokens. The word “tokenization” split in two because the tokenizer decided “token” and “ization” are more useful chunks to know separately.That’s the intuition. Now let’s go deeper.What Is a Token, Technically?A token is the basic unit of text that an LLM reads, processes, and generates. Everything that flows through a language model — your prompt, the system instructions, the model’s reply — is processed as a sequence of tokens.There are roughly three types of tokens:Type Example Notes Full word "the", "is", "and" Very common words are often single tokens Sub-word "token" + "ization" Rare or long words get split Character-level "x", "Z" Very rare in modern tokenizersRule of thumb: 1 token ≈ 4 characters of English text, or roughly ¾ of a word. So 100 tokens ≈ 75 wordsHow Does the Tokenizer Decide Where to Split?This is where it gets interesting. The tokenizer doesn’t follow grammar rules or dictionary definitions. It uses an algorithm called Byte Pair Encoding (BPE).Here’s how BPE works:flowchart TD A["Start: Raw Training Text\n(billions of words)"] --> B["Step 1: Split everything\ninto individual characters"] B --> C["Step 2: Count all adjacent\ncharacter pairs"] C --> D["Step 3: Merge the most\nfrequent pair into one token"] D --> E{"Vocabulary\nsize reached?"} E -- No --> C E -- Yes --> F["Final Vocabulary\n~50,000 tokens"] F --> G["Tokenizer is frozen\nand shipped with the model"]Concrete example:Imagine the word "low" appears 5 times and "lower" appears 40 times in training data.BPE sees l, o, w, e, r as individual characters firstIt notices l+o appears very frequently → merges into loThen lo+w is frequent → merges into lowThen low+e → loweThen lowe+r → lowerAfter enough merges, "lower" becomes a single token because it appears so often it's worth having a dedicated slot for.The Tokenization Pipeline — Step by StepHere’s the full journey from your text to tokens inside the model:flowchart LR A["Your Text\n'My name is Arjun'"] --> B["Tokenizer\n(BPE algorithm)"] B --> C["Token Strings\n['My', ' name', ' is', ' Ar', 'jun']"] C --> D["Token IDs\n[3421, 1438, 318, 1274, 18150]"] D --> E["Embedding Layer\nEach ID → vector of ~4000 numbers"] E --> F["Transformer Layers\n(the actual LLM)"] F --> G["Output Token IDs"] G --> H["Decoded back to text\nby the tokenizer"]Notice step 4 — token IDs get converted into embedding vectors before the model ever sees them. The model doesn’t work with text or even token IDs directly. It works with lists of numbers. But that’s a story for the Parameters blog (Part 3).Why Do Tokens Vary Between Models?This is a nuance that trips up a lot of developers.GPT-4, Claude, and Gemini do NOT share the same tokenizer.Each model trains its own tokenizer on its own dataset. This means:The same sentence can produce a different number of tokens across modelsToken IDs for the same word can be completely different between GPT-4 and ClaudeA prompt that costs X tokens on OpenAI might cost Y tokens on Anthropicflowchart TD A["Input: 'Tokenization is fascinating'"] A --> B["GPT-4 Tokenizer\n→ 4 tokens"] A --> C["Claude Tokenizer\n→ 5 tokens"] A --> D["Gemini Tokenizer\n→ 4 tokens"] B --> E["Different IDs\nDifferent splits\nDifferent costs"] C --> E D --> EThe practical implication: always test token counts on the model you’re actually using. Don’t assume they’re the same.Edge Cases That Will Surprise You1. Numbers are expensive"1234567" → ["123", "456", "7"] (3 tokens)Numbers don’t compress as well as words because they’re more varied in training data.2. Emojis are very expensive"🔥" → ["\xf0\x9f", "\x94\xa5"] (2 tokens, sometimes more)Emojis are multi-byte Unicode characters. The tokenizer often has to use multiple tokens to represent a single emoji.3. Code has its own tokenization behavior# "def calculate_total_price(items):" # → ["def", " calculate", "_total", "_price", "(", "items", "):"]# That's 7 tokens for one function signatureUnderscores, camelCase, and symbols all split differently. This matters when you’re working on code-heavy prompts.4. Non-English text tokenizes less efficientlyEnglish dominates most training corpora, so English tokens are “fuller” — they pack more meaning per token. Hindi, Tamil, or Arabic text often requires more tokens to represent the same meaning. This has real billing implications for multilingual apps.How to Actually Count TokensDon’t guess. Use the tools:For OpenAI:pip install tiktokenimport tiktokenenc = tiktoken.encoding_for_model("gpt-4")tokens = enc.encode("My name is Arjun")print(len(tokens)) # → 4For Anthropic (Claude):import anthropicclient = anthropic.Anthropic()response = client.messages.count_tokens( model="claude-opus-4-5", messages=[{"role": "user", "content": "My name is Arjun"}])print(response.input_tokens)Quick online tools:platform.openai.com/tokenizer — paste any text and see exactly how it splitsWhy Does Any of This Matter?Because tokens are the unit of measurement for everything in the LLM world:Billing is per token (we’ll dig into this in Part 2)Context window is measured in tokens (Part 4)Response speed depends on token count — more tokens = slowerThinking happens in tokens (Part 5)Hallucinations emerge from the token prediction process (Part 6)Every single concept in this series is downstream of this one. Tokens aren’t just a billing quirk — they are the atom that everything else is built from.The Mental Model to KeepAfter everything above, here’s the one thing to carry forward:An LLM doesn’t read text. It reads a sequence of integer IDs, where each ID represents a learned chunk of language. The quality, cost, and behavior of every LLM interaction is shaped by how your text splits into those chunks.The next time you type a prompt, you’re not sending words to the model. You’re sending a list of numbers — and the model’s entire world is built on top of them.What’s NextNow that you understand what tokens are, the natural next question is: who’s counting them, and what does it cost?In Part 2 — LLM Billing: How Input Tokens, Output Tokens and History Add Up, we’ll break down why your API bill is probably higher than you think — and exactly where those extra tokens are hiding.Series: An Engineer’s Explorations in LLM Concepts ( Part 1 of 6 )Tags: #LLM #MachineLearning #NLP #SoftwareEngineering #AIEngineering #Tokenization #GPT #Claude #DeepLearningTokens: The Atom of Everything in Large Language Models was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.