<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: J. Wren</title>
    <description>The latest articles on DEV Community by J. Wren (@jwren).</description>
    <link>https://dev.to/jwren</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4275556%2Fd2eecdc5-9bc0-45e4-ac09-e0d9f38b67e6.png</url>
      <title>DEV Community: J. Wren</title>
      <link>https://dev.to/jwren</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jwren"/>
    <language>en</language>
    <item>
      <title>Is 1 token really 4 characters? Fifty samples through two OpenAI tokenizers</title>
      <dc:creator>J. Wren</dc:creator>
      <pubDate>Tue, 01 Dec 2026 06:07:10 +0000</pubDate>
      <link>https://dev.to/jwren/is-1-token-really-4-characters-fifty-samples-through-two-openai-tokenizers-3llb</link>
      <guid>https://dev.to/jwren/is-1-token-really-4-characters-fifty-samples-through-two-openai-tokenizers-3llb</guid>
      <description>&lt;p&gt;One token is about four characters: that rule of thumb is everywhere. I checked it on 50 text samples. It holds for one kind of text and misses badly on others.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scope.&lt;/strong&gt; I counted with two OpenAI encodings only, &lt;code&gt;cl100k_base&lt;/code&gt; and &lt;code&gt;o200k_base&lt;/code&gt;, through the open-source &lt;code&gt;tiktoken&lt;/code&gt; library. I did not measure Claude or Gemini for this post. Nothing below says how they count tokens.&lt;/p&gt;

&lt;h2&gt;
  
  
  Method
&lt;/h2&gt;

&lt;p&gt;There are 10 samples in each of five categories: English prose, Traditional Chinese, Simplified Chinese, Python code and JSON. I wrote them for this test, so none is copied from a book or a codebase. Each sample is short: one to three sentences, a small function, or one JSON object.&lt;/p&gt;

&lt;p&gt;For every sample I took the character count (&lt;code&gt;len()&lt;/code&gt; in Python) and the token count, then divided characters by tokens. The table shows the average of the ten ratios in each category, with the lowest and highest sample in brackets.&lt;/p&gt;

&lt;h2&gt;
  
  
  Results: characters per token
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Category&lt;/th&gt;
&lt;th&gt;cl100k_base: avg (min to max)&lt;/th&gt;
&lt;th&gt;o200k_base: avg (min to max)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;English prose&lt;/td&gt;
&lt;td&gt;5.15 (4.59 to 5.64)&lt;/td&gt;
&lt;td&gt;5.23 (4.59 to 5.64)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Traditional Chinese&lt;/td&gt;
&lt;td&gt;0.78 (0.70 to 0.87)&lt;/td&gt;
&lt;td&gt;1.18 (1.10 to 1.28)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Simplified Chinese&lt;/td&gt;
&lt;td&gt;0.99 (0.85 to 1.14)&lt;/td&gt;
&lt;td&gt;1.40 (1.16 to 1.56)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Python code&lt;/td&gt;
&lt;td&gt;3.77 (2.81 to 4.29)&lt;/td&gt;
&lt;td&gt;3.74 (2.81 to 4.29)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JSON&lt;/td&gt;
&lt;td&gt;2.66 (1.90 to 3.30)&lt;/td&gt;
&lt;td&gt;2.65 (1.94 to 3.30)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Reading the table
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;English prose&lt;/strong&gt; averages 5.15 and 5.23. Even the lowest sample is 4.59. Four characters per token overestimates the token count here. For a cost estimate that is the safe direction to be wrong in.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chinese&lt;/strong&gt; is the opposite case. Across both scripts and both encodings the averages run from 0.78 to 1.40 characters per token. Traditional Chinese on &lt;code&gt;cl100k_base&lt;/code&gt; averages 0.78, so a single character often costs more than one token. A four-characters estimate would undercount Chinese text by about 2.9x to 5.1x, depending on script and encoding.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Python code&lt;/strong&gt; averages 3.77 and 3.74, close to four. Single samples range from 2.81 to 4.29, so the range crosses four.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JSON&lt;/strong&gt; averages 2.66 and 2.65. The highest sample is 3.30, so every JSON sample sits below four. Quotes, braces and commas tokenize less efficiently than prose.&lt;/li&gt;
&lt;li&gt;The two encodings agree closely on English, code and JSON. The gap shows up on Chinese, where &lt;code&gt;o200k_base&lt;/code&gt; gives more characters per token.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What this does not show
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Ten samples per category show direction, not a multiplier for your data. A larger and more varied corpus would likely move these ranges.&lt;/li&gt;
&lt;li&gt;I tested prose-register Chinese and ordinary Python. Dense technical Chinese, minified code or deeply nested JSON could land elsewhere.&lt;/li&gt;
&lt;li&gt;The samples are short. The numbers say nothing certain about long documents.&lt;/li&gt;
&lt;li&gt;This counts the text alone. A real request also carries system prompts, tool definitions and message formatting.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Get a ratio for your own text
&lt;/h2&gt;

&lt;p&gt;A better number than any rule of thumb is the one from your own prompts. This is all it takes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;tiktoken&lt;/span&gt;

&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"your_prompt.txt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"utf-8"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"cl100k_base"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"o200k_base"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tiktoken&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_encoding&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"tokens,"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"chars per token"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The full per-sample results and the measurement script are published with the original write-up: &lt;a href="https://getllmcalc.com/guides/does-4-characters-equal-1-token" rel="noopener noreferrer"&gt;https://getllmcalc.com/guides/does-4-characters-equal-1-token&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want a quick count in the browser, the same site has a token counter that runs the two GPT encodings locally and uses a four-characters estimate for Claude and Gemini: &lt;a href="https://getllmcalc.com/tools/token-counter" rel="noopener noreferrer"&gt;https://getllmcalc.com/tools/token-counter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;An AI model drafted this post from the published results file. The figures were filled in from that file, not typed from memory.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>llm</category>
      <category>openai</category>
      <category>python</category>
      <category>tokenization</category>
    </item>
  </channel>
</rss>
