Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Blog/Foundations

Why does one emoji have a length of 5, 7 or 17?

One facepalm emoji has length 5 in Python, 7 in JavaScript and 17 bytes on disk. Here is why, plus the Turkish I bug.

Derpx064 Nov · 4 min read
Contents
Why do computers only know numbers?What is a byte, and how is it different?How does UTF-8 pack things?Why does "length" give different answers?What is the Turkish dotless-i bug?So what would I do differently?Sources
0% read · 4 min leftBack to top ↑
On this page0%
Contents
Why do computers only know numbers?What is a byte, and how is it different?How does UTF-8 pack things?Why does "length" give different answers?What is the Turkish dotless-i bug?So what would I do differently?Sources

Quick question. How long is the text "🤦🏽‍♂️"? You see one facepalm. JavaScript reports 7, Python reports 5, and the file on disk takes 17 bytes.

Nobody is wrong. Each one counts a different thing, and that is what makes text secretly hard. Let's look at the layers one at a time.

Why do computers only know numbers?

A computer can't store a letter. It stores numbers, and we agree on a table that lists which number means which letter. In the standard table, 65 means "A" and 66 means "B".

Unicode is the giant shared table. Each entry gets a number called a code point, written like U+0041 for "A". It covers scripts from all over the world, plus emoji.

Code point

The number Unicode gives to one entry in its table. "A" is U+0041. The Unicode range tops out at U+10FFFF.

So a code point is a number in a table. But that's not what lands in your file.

What is a byte, and how is it different?

A code point is an idea. A byte is what actually sits in your file (one byte holds a number from 0 to 255). So we need a rule for turning code points into bytes. That rule is an encoding, and the popular one is UTF-8.

How does UTF-8 do it?

How does UTF-8 pack things?

UTF-8 uses 1 to 4 bytes per code point. Small numbers get fewer bytes, big numbers get more. The rules are in RFC 3629.

Code point rangeBytes
U+0000 to U+007F1
U+0080 to U+07FF2
U+0800 to U+FFFF3
U+10000 to U+10FFFF4

The first range is plain old ASCII, stored as one byte exactly like before. So English text costs 1 byte per letter, and old files stay valid. That is a big reason UTF-8 won.

Now we have enough to crack the facepalm.

Why does "length" give different answers?

The facepalm is built from several code points glued together. Here is the list, step by step:

  1. 🤦 the facepalm face (1 code point, 4 bytes)
  2. 🏽 a skin tone (1 code point, 4 bytes)
  3. A zero width joiner, an invisible glue character (1 code point, 3 bytes)
  4. ♂ the male sign (1 code point, 3 bytes)
  5. A variation selector that asks for the emoji look (1 code point, 3 bytes)

That's 5 code points and 17 bytes. JavaScript counts in UTF-16 units, where the first two code points take 2 units each, so you get 7. Python counts code points, so 5.

Click Next to see the same facepalm counted by each layer. The number changes at each stop.

What you see
Code points
UTF-8 bytes
UTF-16 units

You see one facepalm emoji

Step 1 of 4
One emoji, four ways to count it. Each count is correct for its own layer.
UTF-8 bytes17
UTF-16 units (JavaScript)7
Code points (Python)5
Same facepalm, three correct answers.

So "length" has no single answer until you say what you're counting. And it gets worse with plain letters.

Even "é" can be one code point or two: an "e" plus a combining accent mark. Same look, different length. Comparing them with == can report "not equal" for text that looks identical.

What is the Turkish dotless-i bug?

Turkish has two letters I: one with a dot and one without. The pairs are I with ı (dotless), and İ (dotted capital) with i. English only knows I with i.

So lowercasing "I" depends on the language. In English it gives "i". In Turkish it gives "ı". Unicode even keeps special rules for this in its SpecialCasing file.

English'FILE'.lower() in English: file
→
Turkish'FILE'.lower() in Turkish rules: fıle
Same code, different locale, different word.

The classic bug: code lowercases a keyword like "FILE" to compare it, runs on a machine set to Turkish, and the match fails. The cause is a small difference you cannot see.

The reverse can surprise you too. In Python, 'İ'.lower() isn't one letter. It gives i plus a combining dot, so two code points.

So what would I do differently?

I used to think a string was a list of letters. It's really a stack of layers, and each layer has its own count.

  1. Decide what you're counting: bytes for storage, code points for Unicode work, or what the user sees.
  2. Don't cut a string at a byte or unit position. You can slice an emoji in half.
  3. For case-insensitive matching, use proper case folding, not .lower() and hope.
  4. Save and read files as UTF-8 on purpose, not by accident.
Key takeaways
  • A code point is Unicode's number for an entry. A byte is what the file stores. Those are different things.
  • UTF-8 uses 1 to 4 bytes per code point, and ASCII stays at 1 byte.
  • One thing you see can be many code points, so "length" depends on what you count.
  • Casing depends on language: Turkish I and ı break English assumptions.

Sources

  • F. Yergeau — RFC 3629: UTF-8, a transformation format of ISO 10646
  • Unicode Consortium — SpecialCasing.txt, Turkish and Azeri section
  • Unicode Consortium — UTF, BOM and code points FAQ
ShareXLinkedInEmail
Written by Derpx06A developer who builds AI search tools and the code around them. I explain what I got wrong first, so you can skip it. Spotted a mistake? Tell me — corrections get credited.
Foundations · 3 minWhy is 0.1 + 0.2 not 0.3 in code?Foundations · 4 minHow does Git work inside? (Snapshots, not changes)Foundations · 5 minHow do maps apps find the fastest route?
Start here
01Why is 0.1 + 0.2 not 0.3 in code?02How does Git work inside? (Snapshots, not changes)03How does your computer know the time? (And why it can be wrong)