> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Tokens The Currency of AI

> Explains tokens and tokenization, how text maps to tokens across tokenizers, impacts on model context and cost, and tools and best practices for accurate token counting.

When you send text to a model it doesn't read words the same way people do — it processes tokens. This lesson makes that concrete by using a tokenizer and observing how different inputs map to tokens. Seeing how text becomes tokens helps you reason about two crucial things: how much an interaction costs and how much information a model can process at once.

<Callout icon="lightbulb" color="#1CB2FE">
  Tokens are the atomic units models process. Tokenization can split words into subword pieces, include punctuation and whitespace, and vary by model family. Use a tokenizer when you need precise token counts for budgeting or capacity planning.
</Callout>

The tokenizer used in these examples is tiktokenizer.com. It’s straightforward: paste or type text into the prompt area on the left, pick a tokenizer at the top, and the tool shows how the text is split into tokens and the numeric token IDs on the right. Everything updates live — no submission required. Try different tokenizers because the same text often tokenizes differently across model families.

Let's start with a short English sentence:

```text theme={null}
The quick brown fox jumps.
The·quick·brown·fox·jumps.
976, 4853, 19705, 68347, 65613, 13

Token count
6
```

A human sees five words; the tokenizer shows six tokens — the extra one is the period. Each colored piece in the tokenizer view is a token and the number underneath is its token ID. Remember: the model processes token IDs, not the raw characters.

A token is not the same as a word. Sometimes a whole word maps to a single token; sometimes a word is split into multiple subword tokens depending on the tokenizer vocabulary and rules. Formatting, punctuation, and whitespace matter. For short sentences that difference is small, but for long prompts, documents, or source code those differences add up because the model handles everything you send.

Now let’s try a very long, uncommon word. I looked one up on Merriam‑Webster and pasted it into the tokenizer:

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/MhECTHF5dIfjn_ai/images/AI-Foundations-for-Technical-Professionals/Inside-the-Model/Tokens-The-Currency-of-AI/longest-words-merriam-webster-book-mask.jpg?fit=max&auto=format&n=MhECTHF5dIfjn_ai&q=85&s=29d011a6628fb3133aa258ed0827dd32" alt="A screenshot of a Merriam‑Webster webpage titled &#x22;The Longest Long Words List,&#x22; showing a photo of a very large reference book on a shelf and, below it, a figure wearing a hard hat and a respirator/gas mask." width="1920" height="1080" data-path="images/AI-Foundations-for-Technical-Professionals/Inside-the-Model/Tokens-The-Currency-of-AI/longest-words-merriam-webster-book-mask.jpg" />
</Frame>

Because uncommon words may not appear as single entries in a tokenizer's vocabulary, the tokenizer often breaks them into multiple subword pieces. Example:

```text theme={null}
hippopotomonstrosesquippedaliophobia
2504, 15042, 346, 43960, 302, 2199, 268, 351, 8193, 3010, 141868

Token count
11
```

A small typo or spelling change can increase token count because the tokenizer may no longer find the same subword segments:

```text theme={null}
hippopotomonstrosesquippedaliofphobia
2504, 15042, 346, 43960, 302, 2199, 268, 351, 8193, 280, 726, 36662, 68602

Token count
13
```

Numbers and non‑Latin scripts often split into multiple tokens depending on the tokenizer’s vocabulary and segmentation rules. For example, the digit string "1234567890" can be broken into several tokens:

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/MhECTHF5dIfjn_ai/images/AI-Foundations-for-Technical-Professionals/Inside-the-Model/Tokens-The-Currency-of-AI/tiktokenizer-gpt56-prompt-token-count-1234567890.jpg?fit=max&auto=format&n=MhECTHF5dIfjn_ai&q=85&s=20259b80f48c2f0a42dd0caf109f65f3" alt="A browser screenshot of a web tool titled &#x22;Tiktokenizer for GPT-5.6 and LLM Prompts&#x22; showing a large prompt-builder area on the left and a token analysis panel on the right. The prompt contains &#x22;1234567890&#x22; and the token analysis shows a token count of 4 with tokenized IDs listed." width="1920" height="1080" data-path="images/AI-Foundations-for-Technical-Professionals/Inside-the-Model/Tokens-The-Currency-of-AI/tiktokenizer-gpt56-prompt-token-count-1234567890.jpg" />
</Frame>

```text theme={null}
1234 567890
7633, 19354, 29338, 15

Token count
4
```

Emojis and other special characters may also expand into multiple tokens. For instance, three emojis mapped to six tokens with one tokenizer:

```text theme={null}
🎉✈️🔥
71344, 231, 18632, 230, 15148, 96506

Token count
6
```

If you switch the tokenizer (for example, from a GPT-5.6-style tokenizer to a GPT-2-style tokenizer), the same emoji sequence can produce a different tokenization and token count:

```text theme={null}
🎉✨🔥
8582, 236, 231, 26486, 230, 37929, 8582, 242, 98

Token count
9
```

Tools like tiktokenizer may indicate whether a tokenization is exact or estimated. Some models publish their encodings so tools can reproduce exact counts; others require estimation. Always check whether the tokenizer you used provides an exact or estimated count before relying on it for budgeting or capacity planning.

Chat-style requests typically include extra structure beyond a user's visible text — system instructions, assistant messages, conversation history, retrieved documents, and tool definitions. Those all contribute to the overall token count. Even a short chat exchange including system delimiters can add many tokens:

```text theme={null}
`<|im_start|>system<|im_sep|>You are a helpful assistant<|im_end|><|im_start|>user<|im_sep|>Evaluate this markdown file and provide a summary for a devops qa engineer<|im_end|><|im_start|>assistant<|im_sep|>`
200264, 17360, 200266, 3575, 553, 261, 10297, 29186, 200265, 200264, 1428, 200266, 112737, 495, 116713, 1974, 326, 3587, 261, 18522, 395, 261, 3947, 4645, 25002, 36894, 200265, 200264, 173781, 200266

Token count
30
```

Because system prompts and chat-format delimiters consume tokens, consider the entire request payload (system messages, conversation context, retrieved data) when estimating usage — not just the user's current message.

Tokens also translate directly to cost: models are typically priced by the number of tokens processed (input + output). For example, a model’s pricing might list a "price per 1M tokens" for input and output — see OpenAI’s pricing for reference. A tiny 30-token prompt costs almost nothing, but as you add context, documents, or request longer outputs, costs increase rapidly.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/MhECTHF5dIfjn_ai/images/AI-Foundations-for-Technical-Professionals/Inside-the-Model/Tokens-The-Currency-of-AI/openai-pricing-gpt56-sol-terra-luna.jpg?fit=max&auto=format&n=MhECTHF5dIfjn_ai&q=85&s=110ddcfd10e24b4d089872b506d2565a" alt="A screenshot of the OpenAI Developers pricing page showing a &#x22;Flagship models&#x22; table with per‑1M token prices for gpt-5.6‑sol, gpt-5.6‑terra, and gpt-5.6‑luna. The site navigation and sidebar are also visible along with notes about regional processing and Fast mode." width="1920" height="1080" data-path="images/AI-Foundations-for-Technical-Professionals/Inside-the-Model/Tokens-The-Currency-of-AI/openai-pricing-gpt56-sol-terra-luna.jpg" />
</Frame>

When choosing a model, balance capability against cost. Frontier models deliver strong capabilities but are expensive per 1M tokens; smaller or specialized models are usually more cost‑effective for many tasks.

Tokenization examples at a glance:

| Input example | Token IDs (example) | Token count |
| - | -: | -: |
| The quick brown fox jumps. | `976, 4853, 19705, 68347, 65613, 13` | 6 |
| hippopotomonstrosesquippedaliophobia | `2504, 15042, 346, 43960, 302, 2199, 268, 351, 8193, 3010, 141868` | 11 |
| hippo... with a typo | `2504, 15042, 346, 43960, 302, 2199, 268, 351, 8193, 280, 726, 36662, 68602` | 13 |
| `1234567890` | `7633, 19354, 29338, 15` | 4 |
| Emoji sequence | `71344, 231, 18632, 230, 15148, 96506` | 6 |
| Chat-style payload | `200264, 17360, 200266, ...` | 30 |

Best practices and quick tips

* Track the entire request: include system prompts, conversation history, retrieved docs, and tool definitions when estimating tokens.
* Prefer token-aware tools or libraries (like official encodings when available) for exact counts.
* Remove unneeded history, compress or summarize long retrieved documents, and use smaller models for tasks where high capability isn’t required to reduce cost.
* Monitor token usage and cost regularly; token behavior can change across model versions and tokenizer updates.

<Callout icon="warning" color="#FF6B6B">
  Estimating tokens with the wrong tokenizer may mislead budgeting and capacity planning. Always confirm whether a tokenizer reports exact or estimated counts and use the encoder associated with the target model when accurate accounting matters.
</Callout>

Summary

* Tokens are the unit models process; text is converted to token IDs before the model handles it.
* Tokenization depends on the tokenizer and model family; the same text can yield different token counts across models.
* Token count affects how much information a model can consider (the context window) and how much an interaction costs.
* Always consider the full request payload — system messages, history, retrieved data — when estimating token usage, not just the visible user input.

For further reading:

* tiktokenizer: [https://www.tiktokenizer.com](https://www.tiktokenizer.com)
* OpenAI pricing and model documentation: [https://platform.openai.com/pricing](https://platform.openai.com/pricing)
* Tokenization and encodings (model-specific docs and libraries)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/ai-foundations-for-technical-professionals/module/26f7dd1e-96fe-441e-a971-4e48f074c9ce/lesson/5c7de9e5-12d9-4946-99f5-93369b0e3e0b" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.