How many tokens is a Markdown file? Count and trim notes for AI context
A Markdown file is about one token per four characters of English, so a 4,000-character note is near 1,000 tokens. How to count it and keep notes cheap.

A Markdown file's token count is roughly its length in characters divided by four, for English text. That is the rule of thumb OpenAI publishes: one token is about four characters, or about three quarters of a word, so a 4,000-character note costs around 1,000 tokens. Markdown syntax adds very little on top of the words, and the exact number depends on the model's tokenizer, so count with an official tool when the figure matters.
This guide covers quick estimates, exact counts with free tools, what the same note costs as Markdown, JSON and XML, and how to keep a folder of notes cheap when you send it to a model.
How do you estimate tokens from a file's size?
Measure characters or words, then apply OpenAI's ratios from What are tokens and how to count them (checked November 2026):
| You know | Rough token count |
|---|---|
| Characters | characters ÷ 4 |
| Words | words ÷ 0.75 (100 tokens ≈ 75 words) |
| A 1,500-word note | about 2,000 tokens |
| 40,000 characters of English text | about 10,000 tokens |
On a Mac or Linux, wc gives you the inputs:
wc -m launch-plan.md # characters
wc -w launch-plan.md # words
wc -c counts bytes rather than characters. For plain English the two are about the same, but accented letters, emoji and most non-Latin scripts take more than one byte per character. OpenAI's article also notes that other languages "can have different relationships between characters, words, and tokens," so the four-characters rule is for English only.
How do you count tokens exactly?
Use the tokenizer of the model you will send the text to. Three free options:
-
OpenAI's Tokenizer page at platform.openai.com/tokenizer. Paste text and it shows the count and how the text was split.
-
tiktoken, OpenAI's open-source tokenizer library. It runs on your computer, needs no API key, and downloads the encoding file once:
pip install tiktoken python3 -c "import tiktoken,sys; e=tiktoken.get_encoding('o200k_base'); print(len(e.encode(open(sys.argv[1]).read())))" launch-plan.mdo200k_baseis the encoding tiktoken returns forgpt-4o. For another OpenAI model, usetiktoken.encoding_for_model("model-name"). -
Anthropic's token counting endpoint,
/v1/messages/count_tokens. Anthropic's token counting docs say it is "free to use" with its own rate limits, and that the result is an estimate. It needs an API key.
Counts are not portable between models. Anthropic's docs say Claude Opus 4.7 and later models use a newer tokenizer on which "the same input text produces approximately 30 percent more tokens than on earlier models," and advise recounting rather than reusing old numbers. The same applies across vendors.
Does Markdown formatting add many tokens?
Less than other ways of adding structure. We wrote one short note three ways and counted each with tiktoken 0.12.0 and the o200k_base encoding on 2026-11-27. You can reproduce it by pasting the same text into the script above.
The Markdown version:
# Launch plan
- Owner: Mina
- Due: 2026-12-15
- Status: In review
## Open questions
- Which stores ship first?
- Who signs off on pricing?
The JSON version had the same fields with two-space indentation ("title": "Launch plan", "open_questions": [...]), and the XML version wrapped each field in a tag (<owner>Mina</owner>).
| Same note as | Characters | Tokens (o200k_base) |
|---|---|---|
| Markdown | 142 | 43 |
| JSON, indented | 187 | 61 |
| JSON, minified | 152 | 42 |
| XML | 259 | 78 |
Markdown and minified JSON cost about the same here, while indented JSON and XML cost more because of whitespace, quotes and closing tags. With cl100k_base, the older encoding, the Markdown and indented JSON versions came to 44 and 61 tokens, so the gap held. The note is tiny, and a different note will give different ratios; the useful point is that heavy markup costs tokens and Markdown is light. Which format to use for what part of a prompt is a separate question, covered in Markdown vs JSON vs XML in prompts.
What makes a note expensive as context?
Mostly things other than the prose. In the same test run:
- Long link URLs.
See the [store guidelines](https://developer.apple.com/app-store/review/guidelines/#performance) first.was 23 tokens. Without the URL, 6. A note full of links can spend more on addresses than on text. - Tables. Three rows of task, owner and date came to 56 tokens as a Markdown table and 42 as a list (
- Store listing: Mina, 2026-12-01). Pipes, the separator row and any padding spaces all count. A table is still the clearer choice when the model has to compare columns, so keep the tables that carry structure and drop decorative ones. The tables page shows the minimal syntax. - Pasted clutter. HTML left over from a web page, an image embedded as a base64 data URI, and tracking parameters on URLs are long strings of text the model reads in full.
- Repeated boilerplate. A template header copied into every note is paid for once per note.
- Front matter. A few lines of YAML are cheap, but large metadata blocks repeated across hundreds of notes add up.
How do you keep notes cheap as AI context?
Send less, and send it in a stable order.
- Pick notes, not the folder. The cheapest token is the one you do not send. Choose the notes that answer the question, or keep a short summary note per project and send that first. Using Markdown notes as AI context covers how to choose.
- One topic per note. Small, focused notes let you include exactly what is needed instead of a long file with one relevant section.
- Trim links the model does not need. Keep the link text and drop the URL, or move URLs to a references list at the end that you can leave out.
- Clean pastes before they become notes. Strip HTML, data URIs and tracking parameters once, so every later prompt is lighter.
- Put stable notes first. Both OpenAI and Anthropic offer prompt caching for a repeated prefix. OpenAI's prompt caching guide says it is on by default for supported models and advises putting "stable developer instructions and shared reference material first." Anthropic's prompt caching docs price cache reads at a fraction of normal input (0.1 times on most models) and require the cached part to be identical. Both have a minimum prompt length, so caching helps with large, repeated context rather than single short notes.
To find the heavy notes in a folder, this script lists the total and the ten largest, skipping hidden folders such as .git:
import pathlib, sys, tiktoken
enc = tiktoken.get_encoding("o200k_base")
folder = pathlib.Path(sys.argv[1])
rows = []
for path in folder.rglob("*.md"):
if any(part.startswith(".") for part in path.parts):
continue
text = path.read_text(encoding="utf-8")
rows.append((len(enc.encode(text)), path))
rows.sort(reverse=True)
print(f"{sum(n for n, _ in rows)} tokens in {len(rows)} notes")
for n, path in rows[:10]:
print(f"{n:>7} {path.relative_to(folder)}")
Save it as count_tokens.py and run python3 count_tokens.py ~/Notes. The counts are for OpenAI's encoding; Claude and Gemini tokenize differently, so treat them as a ranking of which notes are heavy rather than a bill. For the bigger picture of how files become context, see context engineering with plain files.
Trimming notes in Noteline
Noteline, which we make, does not count tokens and has no AI features. It helps with the trimming. Open your notes folder (Cmd+O on a Mac, Ctrl+O on Windows and Linux), then use Find in Folder (Cmd+Shift+F or Ctrl+Shift+F) to find every note with ](http or a pasted <div, and fix them in place. Source view (Cmd+Shift+M or Ctrl+Shift+M) shows the raw Markdown, which is what a model reads, including URLs that live preview hides behind link text. Notes stay plain .md files, so the script above reads them directly. The iPhone, iPad and Android apps are free.