---
title: "DeepSeek Tokenizer: Vocab Size, Token Counts and Cost"
description: "The DeepSeek tokenizer is byte-level BPE with a 128,000-token base vocabulary. How to count tokens offline, and how its counts compare with GPT."
canonical: https://vynaris.com/blog/deepseek-tokenizer
author: "Dhrumil Barot"
author_bio: "Dhrumil is an AI inference and LLM infrastructure expert. Dhrumil built Vynaris to make model access, routing and pricing simple and transparent for developers."
published: 2026-11-14
updated: 2026-11-14
---

# DeepSeek Tokenizer: Vocab Size, Token Counts and Cost

Published 2026-11-14 · By [Dhrumil Barot](https://vynaris.com/about#founder), Founder

The DeepSeek tokenizer is byte-level BPE with a 128,000-token base vocabulary. How to count tokens offline, and how its counts compare with GPT.

**TL;DR:** The DeepSeek tokenizer is a byte-level BPE tokenizer with a 128,000-token base vocabulary (129,280 IDs including special tokens), shared by DeepSeek V3, R1, V4 Pro and V4.1 Flash. On English, code and JSON it produces 2-6% more tokens than OpenAI's o200k_base; on Chinese it produces about 19% fewer. You can count tokens offline with the tokenizer.json from DeepSeek's official zip.

DeepSeek introduced this byte-level BPE (byte pair encoding) tokenizer with DeepSeek-V3 and carried its 128,000 base tokens unchanged into DeepSeek-V4 and V4.1. The V4 files add 1,283 special tokens on top (chat roles, tool calls, image placeholders), so token IDs run from 0 to 129,279. We counted the same six texts with the DeepSeek tokenizer, GPT's o200k_base and Qwen3's tokenizer. A 53-word English paragraph costs 65 DeepSeek tokens versus 64 on o200k_base. The same paragraph in Chinese costs 58 DeepSeek tokens versus 72. Every count below is reproducible from public files; the commands are in the "count locally" section.

## What is the DeepSeek tokenizer built on?

DeepSeek uses byte-level BPE with an extended vocabulary of 128K tokens, per section 4.1 of the [DeepSeek-V3 technical report](https://arxiv.org/html/2412.19437v1). The report says the pretokenizer and the tokenizer's training data were "modified to optimize multilingual compression efficiency", and that V3 added tokens that combine punctuation with line breaks.

That last change has a known side effect. DeepSeek calls it token boundary bias: a multi-line prompt without a final line break can tokenize differently from what the model saw in training. DeepSeek's fix was to randomly split a share of those combined tokens during training. In practice, ending prompts with a newline is still the safer habit.

We compared the tokenizer.json files directly. The 128,000-entry base vocabulary and the pretokenizer are byte-for-byte identical across [DeepSeek-V3](https://huggingface.co/deepseek-ai/DeepSeek-V3), [DeepSeek-R1](https://huggingface.co/deepseek-ai/DeepSeek-R1), DeepSeek-V4-Pro-0813, [DeepSeek-V4.1-Flash](https://huggingface.co/deepseek-ai/DeepSeek-V4.1-Flash) and the official API zip. Only the special tokens changed:

| Model | Base vocab | Special tokens | Highest token ID |
| --- | --- | --- | --- |
| deepseek-llm-7b-base (V1, 2023) | 100,000 | 15 | 100,014 |
| DeepSeek-V3 / R1 | 128,000 | 818 | 128,814 |
| DeepSeek-V4-Pro-0813 | 128,000 | 1,283 | 129,279 |
| DeepSeek-V4.1-Flash (API: deepseek-flash) | 128,000 | 1,283 | 129,279 |

So a token count you measured on V3 still holds on V4 Pro and V4.1 Flash for plain text. Anthropic's newer tokenizer is the opposite case (see below).

## How does BPE split text into chunks?

The tokenizer works in two passes. First a pretokenizer cuts the text into chunks with three regex rules, then BPE merges bytes inside each chunk into the longest known tokens.

The three pretokenizer rules in tokenizer.json:

1. **Digits in groups of 1 to 3.**  `1234567` becomes `123`, `456`, `7`. A price like `3.14159` becomes `3`, `.`, `141`, `59`.
2. **Chinese and Japanese runs isolated.** Any run of CJK ideographs, hiragana or katakana (`[一-龥぀-ゟ゠-ヿ]+`) becomes its own chunk, so BPE can learn multi-character Chinese words such as 退款 (refund) as single tokens.
3. **Words, punctuation and whitespace.** A GPT-style rule keeps a leading space with each word (` tickets`), and joins punctuation with following line breaks (`:` plus newline is one token).

![How DeepSeek turns raw text into billed tokens, from pretokenizer to API usage](https://cdn.sanity.io/images/u1qdn8dx/production/c9b78d6631dd28ee60b8b00c0117efbae4486a17-1344x326.png?w=1440&fit=max&auto=format)

*Offline counts cover the first four boxes; the API bill includes the template tokens too.*

The video below walks through the same BPE training and merge process on a toy corpus. DeepSeek's version runs on bytes instead of characters, but the merge rules work identically.

Video: [Byte Pair Encoding Tokenization](https://www.youtube.com/watch?v=HEikzVL-lZU&t=32s) (Hugging Face)

Hugging Face's course video shows how a BPE tokenizer is trained: split words into base units, count adjacent pairs, merge the most frequent pair into a new token, and repeat until the vocabulary reaches its target size. It then tokenizes a new word by replaying the merge rules.

- [0:32](https://www.youtube.com/watch?v=HEikzVL-lZU&t=32s) BPE splits words into frequent subword units
- [1:32](https://www.youtube.com/watch?v=HEikzVL-lZU&t=92s) Building the initial vocabulary from characters
- [2:09](https://www.youtube.com/watch?v=HEikzVL-lZU&t=129s) Counting every adjacent token pair
- [2:41](https://www.youtube.com/watch?v=HEikzVL-lZU&t=161s) Writing the first merge rule
- [4:41](https://www.youtube.com/watch?v=HEikzVL-lZU&t=281s) Tokenizing a new word with the learned merges

## How do I count DeepSeek tokens locally?

Use the tokenizer.json from DeepSeek's official download. The [Token & Token Usage page](https://api-docs.deepseek.com/quick_start/token_usage) links `deepseek_v4_tokenizer.zip`, which contains `tokenizer.json`, `tokenizer_config.json` and a three-line demo script that needs `transformers`.

You don't need `transformers` or PyTorch. The `tokenizers` library reads the file directly:

```bash
pip install tokenizers
curl -LO https://cdn.deepseek.com/api-docs/deepseek_v4_tokenizer.zip
unzip deepseek_v4_tokenizer.zip
```

```python
from tokenizers import Tokenizer

tok = Tokenizer.from_file("deepseek_v4_tokenizer/tokenizer.json")

text = "Our support team answers about 1,200 tickets a day."
enc = tok.encode(text, add_special_tokens=False)
print(len(enc.ids))   # 13
print(enc.tokens)     # ['Our', 'Ġsupport', 'Ġteam', ..., 'Ġday', '.']
```

The `Ġ` is how byte-level BPE displays a leading space. `tokenizer_config.json` sets `add_bos_token` to false, so `"Hello!"` encodes to `[19923, 3]`, two tokens, with or without special tokens.

If you already use `transformers`, DeepSeek's own demo is equivalent:

```python
import transformers

tokenizer = transformers.AutoTokenizer.from_pretrained("./deepseek_v4_tokenizer")
print(len(tokenizer.encode("Hello!")))   # 2
```

Your offline count will be slightly lower than the `usage.prompt_tokens` the API returns. Rendering the zip's chat template around one user message adds 3 tokens: `<｜begin▁of▁sentence｜>`, `<｜User｜>` and `<｜Assistant｜>`. A system prompt adds its own text on top (6 tokens for "You are a support agent."). Tool definitions and images add more. DeepSeek's docs are explicit that the API's usage figure is what you are billed on, so treat offline counts as a pre-flight estimate:

```python
from openai import OpenAI

client = OpenAI(base_url="https://api.deepseek.com", api_key="sk-...")
r = client.chat.completions.create(
    model="deepseek-flash",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(r.usage.prompt_tokens, r.usage.completion_tokens)
```

## How many tokens does DeepSeek use per English word versus GPT and Claude?

On English prose, DeepSeek uses about 1.23 to 1.26 tokens per word, within 4% of GPT's o200k_base. We counted six texts with four tokenizers (counts captured 2026-11-14, `tokenizers` 0.23.3, `tiktoken` 0.14.0):

| Text | Characters | DeepSeek V3/V4 | o200k_base (GPT-4o, GPT-5) | Qwen3 | DeepSeek vs o200k |
| --- | --- | --- | --- | --- | --- |
| English support brief (53 words) | 287 | 65 | 64 | 68 | +1.6% |
| Zen of Python (144 words) | 857 | 182 | 176 | n/a | +3.4% |
| Python function | 340 | 113 | 108 | 121 | +4.6% |
| CPython 3.13 textwrap.py | 19,939 | 4,715 | 4,491 | 4,478 | +5.0% |
| JSON ticket record | 286 | 95 | 90 | 96 | +5.6% |
| Chinese support brief | 103 | 58 | 72 | 61 | -19.4% |

The older cl100k_base (GPT-4, GPT-3.5) stays within 3% of o200k_base on English and code but needs 107 tokens for the Chinese text, 84% more than DeepSeek. DeepSeek's own V1 tokenizer needed 140 tokens for the Python function, 24% more than V3. The 2024 rewrite paid off most on code and Chinese.

![Token counts for the same text: DeepSeek is close on English, lower on Chinese](https://cdn.sanity.io/images/u1qdn8dx/production/e7b1e0fb31082215117c495c3a69ad336b0e0a2f-1344x456.png?w=1440&fit=max&auto=format)

*Same input strings; counts exclude chat template tokens.*

**What about Claude?** Anthropic doesn't publish Claude's tokenizer, so there is no local count to put in the table. The exact number comes from the free `count_tokens` endpoint, which is rate-limited by usage tier. Anthropic's [token counting docs](https://docs.claude.com/en/docs/build-with-claude/token-counting) also state that Claude Opus 4.7 and later models, including Claude Fable 5.1 and 5.2, use a newer tokenizer that produces roughly 30% more tokens for the same text than earlier Claude models. Count with the model ID you will actually call:

```python
import anthropic

client = anthropic.Anthropic()
r = client.messages.count_tokens(
    model="claude-fable-5-2",
    messages=[{"role": "user", "content": "Our support team answers about 1,200 tickets a day."}],
)
print(r.input_tokens)
```

For GPT-6 models, OpenAI doesn't say which encoding they use; tiktoken 0.14.0 maps only up to the `gpt-5` prefix to o200k_base. OpenAI's [input token count endpoint](https://developers.openai.com/api/docs/guides/token-counting) returns the exact figure, including role and formatting tokens.

## Is DeepSeek's "0.3 tokens per character" rule accurate?

It overestimates English. DeepSeek's docs give 1 English character ≈ 0.3 token and 1 Chinese character ≈ 0.6 token. On our samples, English prose came in at 0.21 to 0.23 tokens per character and the 20,000-character Python file at 0.24. Chinese measured 0.56, close to the documented 0.6.

For the 287-character English brief, the rule predicts 86 tokens; the tokenizer returns 65. That 32% gap is fine for a budget ceiling and too loose for anything that compares models.

## Does tokenizer efficiency change the real cost per request?

Yes, but only when the text is non-English or the prices are close. Per-token prices are only comparable if both models cut your text into the same number of tokens. For English they nearly do; for Chinese they don't.

**Worked example.** A support desk sends 36,000 tickets a month (1,200 a day). Each ticket is the support brief above scaled 30x as input and 5x as output. We price DeepSeek's `deepseek-flash` at the peak rate ($0.30 per 1M input on cache miss, $1.20 per 1M output, from the [DeepSeek pricing page](https://api-docs.deepseek.com/quick_start/pricing), captured 2026-11-14). We set it against `gpt-5-mini` at $0.25 input and $2.00 output per 1M, from [OpenAI's pricing page](https://developers.openai.com/api/docs/pricing), and count its tokens with o200k_base. Output length is held equal in characters so only the tokenizer changes.

| Monthly workload, 36,000 tickets | Input tokens per ticket | Output tokens per ticket | Monthly cost |
| --- | --- | --- | --- |
| English, deepseek-flash (peak) | 1,950 | 325 | $35.10 |
| English, gpt-5-mini | 1,920 | 320 | $40.32 |
| Chinese, deepseek-flash (peak) | 1,740 | 290 | $31.32 |
| Chinese, gpt-5-mini | 2,160 | 360 | $45.36 |
| Chinese, gpt-5-mini priced on DeepSeek counts | 1,740 | 290 | $36.54 |

The derivation for the Chinese gpt-5-mini row: 36,000 × 2,160 = 77.76M input tokens × $0.25 = $19.44, plus 36,000 × 360 = 12.96M output tokens × $2.00 = $25.92, for $45.36.

![Chinese workload: the tokenizer adds $8.82 a month to the gpt-5-mini estimate](https://cdn.sanity.io/images/u1qdn8dx/production/7f59d16ebd2e8b58ac02a656c2d0aec0d0e3efbd-1344x410.png?w=1440&fit=max&auto=format)

*Same text; only the tokenizer and the per-token price change.*

Three things fall out of the table:

- **On English, the tokenizer is noise.** DeepSeek needs 1.6% more tokens and the bill difference ($35.10 vs $40.32) comes almost entirely from list prices.
- **On Chinese, a naive estimate is off by 24%.** Pricing gpt-5-mini with DeepSeek's token counts gives $36.54; the real figure is $45.36. The cheaper-looking input price of gpt-5-mini disappears once you count its tokens.
- **Time of day matters more than the tokenizer.** DeepSeek's off-peak rates are half the peak rates (peak is 01:00-04:00 and 06:00-10:00 UTC on weekdays), so the Chinese workload drops from $31.32 to $15.66. That 50% swing is more than 30 times the 1.6% English tokenizer gap.

If you want to run these numbers with your own token counts, plug them into the [LLM cost calculator](https://vynaris.com/calculator) or the [LLM API cost spreadsheet template](https://vynaris.com/blog/llm-api-cost-spreadsheet-template).

Comparing per-token prices is where most model-choice spreadsheets go wrong, and it is the problem [Vynaris](https://vynaris.com) is built around. It is an OpenAI- and Anthropic-compatible gateway: you change the base URL, it starts each task on a frontier model and routes down only when eval evidence shows a cheaper model handles that task. Each call's receipt shows which model ran and what it cost, counted by that model's own tokenizer.

## DeepSeek vs Claude: which is easier to estimate?

DeepSeek's tokenizer is public and stable across versions; Claude's is private and changed with Opus 4.7. That changes how you estimate:

|  | DeepSeek (V3 to V4.1) | Claude (Opus 4.7 and later) |
| --- | --- | --- |
| Algorithm | Byte-level BPE, published | Not published |
| Base vocabulary | 128,000 | Not published |
| Offline counting | Yes, tokenizer.json | No |
| Exact count before calling | Local tokenizer plus template tokens | Free count_tokens endpoint |
| Changed between versions | No, since V3 | Yes, about 30% more tokens from Opus 4.7 |

To see what tokenizer changes did to Claude's own pricing math, read our breakdown of [Claude Fable 5.1 vs Opus 5 token efficiency](https://vynaris.com/blog/claude-fable-51-vs-opus-5-token-efficiency-break-even).

## Common mistakes in offline counts

- **Using the wrong file.** The repo for deepseek-llm-7b-base still ranks for "deepseek tokenizer", but that is the 100,000-token V1 tokenizer. It counted 140 tokens for our Python function where V4 counts 113.
- **Forgetting the template.** Each message adds role tokens; a 50-turn conversation adds more than a single prompt suggests.
- **Missing final newline.** Because punctuation and line breaks merge into one token, `"Answer:"` and `"Answer:\n"` end on different tokens. Keep prompt endings consistent.
- **Comparing prices across tokenizers.** For Chinese, Japanese or mixed-language traffic, compare cost per task, not cost per 1M tokens. Our [MiniMax vs DeepSeek cost per task comparison](https://vynaris.com/blog/minimax-vs-deepseek) shows the method on a full workload.
- **Assuming providers count the same.** Third-party hosts serve the same open-weight DeepSeek models, but their prices differ a lot: see the [DeepSeek V4 Pro price spread across 17 providers](https://vynaris.com/blog/deepseek-v4-pro-17-provider-price-spread).

## FAQ

### How big is the DeepSeek vocabulary?

128,000 base tokens learned by BPE, plus 1,283 special tokens in V4 and V4.1 (818 in V3 and R1). The model's embedding table has 129,280 rows, which is the `vocab_size` in DeepSeek-V3's config.json.

### Is DeepSeek V4's tokenizer the same as V3's?

For ordinary text, yes. The 128,000-token base vocabulary and the pretokenizer rules are identical; V4 adds 465 special tokens for its chat, tool-call and image formats. DeepSeek-R1 shares V3's tokenizer exactly.

### Does DeepSeek use the same tokenizer as Qwen3?

No. Qwen3 uses its own byte-level BPE with 151,643 base tokens. On our samples Qwen3 needed 68 tokens for the English brief (DeepSeek 65), 121 for the Python function (DeepSeek 113) and 61 for the Chinese brief (DeepSeek 58).

### How many DeepSeek tokens is 1,000 English words?

About 1,230 to 1,260 tokens for ordinary prose, based on our two English samples (1.23 and 1.26 tokens per word). Code and JSON run higher per word because symbols and indentation become separate tokens.

### Is there an online DeepSeek token counter?

Several sites offer one, but the most reliable counter is the official tokenizer.json, because it is the exact file DeepSeek publishes for this purpose. Any online tool should return the same counts as the Python snippet above; if it doesn't, it is using a different tokenizer.

### Why does the API report more tokens than my local count?

The API counts the chat template (beginning-of-sentence and role tokens), the system prompt, tool definitions and images. A single user message adds 3 tokens on top of the raw text in our test.

## About the author

[Dhrumil Barot](https://vynaris.com/about#founder), Founder. Dhrumil is an AI inference and LLM infrastructure expert. Dhrumil built Vynaris to make model access, routing and pricing simple and transparent for developers. [LinkedIn](https://www.linkedin.com/in/bdhrumil) · [X](https://x.com/fyidhrumil)
