How a message becomes bytes

The message Aé has two characters. In UTF-8 it takes three bytes. Where does the extra byte come from?

Follow the worked example below to see how Aé becomes three UTF-8 bytes and how those bytes turn back into text.

Characters become bytes

The messages in Lesson 1.1 started as text. An encoding is a rule for turning that text into bytes. Unicode assigns characters numbers called code points. UTF-8 uses the number to work out which bytes to write. A code point that UTF-8 can encode uses one to four bytes, as specified in RFC 3629 §3.

Two ways to write a byte

A bit is a single 0 or 1. A byte is eight bits. In hexadecimal, or hex, a digit has 16 possible values: 0 through 9 followed by A through F. Each hex digit describes four bits. The two digits of 41 describe 0100 and 0001, giving a shorter way to write the same byte as 01000001.

Encoding Aé as UTF-8
CharacterHex bytesBinary bytes
A4101000001
éC3 A911000011 10101001

In a one-byte UTF-8 encoding, the first bit is 0, leaving seven bits for a number from 0 to 127. The code point for A is 65 (U+0041), so it fits. The code point for é is 233 (U+00E9), so UTF-8 uses two bytes for it. In order, the message takes three bytes: 41 C3 A9.

Decode the bytes back to text

The first byte, 41, starts with a 0 bit, so the decoder reads it on its own as A. The first bits of C3 are 110, which tells the decoder to read two bytes. It takes A9 with it because A9 starts with 10, the marker for a byte that continues a character. The remaining bits of the pair give the number for é.

Check your understanding

Suppose the message is éA. Which character takes two bytes, and what order will the bytes appear in? Which byte’s binary form starts with 110, and what does that tell the decoder?

Show the answer

é takes two bytes and comes first, so the sequence is C3 A9 41. The first byte, C3, is 11000011. The 110 at the start tells the decoder to read this byte and one more together.

Modern ciphers work with data as bits. You’ll flip bits like these with XOR in Lesson 3.2.