L
LLLOS.ai
Learn
L

Ask Your Tutor · Computer Science

How do computers know where one UTF-8 character ends and the next begins?

From NCERT Asked by Anonymous from New Orleans, United States 23 Oct 2026, 5:21 PM IST Updated

In one line

A computer checks each byte (piece of data) to see how many bytes make up one UTF-8 character, using special patterns at the start of each character.

The rule

In UTF-8, the first byte of a character tells how many bytes the character uses, so computers can know where one character ends and the next begins.

Let's understand it simply

Imagine you have a box of ladoos (sweets), but some ladoos are packed alone, some in pairs, and some in groups of three or four. Each group has a sticker on the first ladoo saying how many are in that group. When you open the box, you look at the sticker on the first ladoo, count that many, and then look for the next sticker. This is how computers read UTF-8: each character starts with a special code that says how many bytes it has.

How it works

  1. The computer reads the first byte.
  2. It checks the pattern of the first few bits (the smallest pieces of data, just 0 or 1).
  3. If the first bit is 0, it's a 1-byte character (like English letters).
  4. If it starts with 110, it's a 2-byte character.
  5. If it starts with 1110, it's a 3-byte character.
  6. If it starts with 11110, it's a 4-byte character.
  7. The computer then reads the next 1, 2, or 3 bytes as part of the same character, based on the pattern.
  8. After finishing, it repeats the process for the next character.
How a computer reads UTF-8 characters
  1. Read the first byte
  2. Check the starting bits to find character length
  3. Read the needed number of bytes
  4. Move to the next character and repeat

The story behind it

UTF-8 was created in 1992 by Ken Thompson and Rob Pike. They wanted a way for computers to handle all the world's languages, not just English. Earlier systems used fixed sizes, which wasted space or couldn't handle all characters. UTF-8 solved this by using short codes for simple characters and longer ones for rare or complex ones.

Where you see it in real life

  • Sending a WhatsApp message: Emojis use 2, 3, or 4 bytes, while English letters use 1 byte. The app reads the message byte by byte.
  • Browsing a Hindi news website: The Devanagari letters use 3 bytes each, and the browser knows where each letter starts and ends.
  • Saving a contact with a Tamil name: The phone uses UTF-8 to store and read the name correctly.
  • Reading a PDF with both English and Chinese: The computer splits the text into characters using UTF-8 rules.

Why it matters

  • Lets computers handle any language, emoji, or symbol in one file.
  • Saves space for common letters (like English) and allows rare ones (like Sanskrit or Japanese).
  • Prevents text from getting jumbled or broken when sharing files or messages.
  • Used in websites, apps, and almost every modern device.

Common mistakes

  • Thinking every character is 1 byte: Some are 2, 3, or 4 bytes.
  • Not checking the first byte's pattern: This can break the text and show strange symbols (like boxes or question marks).
  • Mixing up UTF-8 with other encodings (like UTF-16): They use different rules.

Remember it

The first byte of a UTF-8 character tells how many bytes to read for that character—like a sticker on a box of ladoos.

Check yourself

How does a computer know if a UTF-8 character is 1, 2, 3, or 4 bytes long?

By checking the pattern of the first byte's bits.

Why can't we just read one byte for every character in UTF-8?

Because some characters need more than one byte, like emojis or Hindi letters.

What happens if the computer starts reading from the middle of a UTF-8 character?

It will show broken or wrong symbols, because it misses the start pattern.

Quick recap

  • UTF-8 uses patterns in the first byte to show character length.
  • Some characters use 1 byte, others use 2, 3, or 4 bytes.
  • The computer checks each byte's starting bits to decide.
  • This lets computers handle all languages and emojis.
  • Mixing up byte boundaries can cause broken text.
Written by the LLOS.ai tutor, checked against NCERT chapters. Asked by Anonymous from New Orleans, United States on 23 Oct 2026, 5:21 PM IST