TEXT ENCODING

Tracing a non-ASCII letter through UTF-8 and Base64

Base64 in this tool encodes bytes, and the bytes of a text come from UTF-8. The single letter é therefore reaches the Base64 step as two bytes, which is why its encoded form is four characters long.

Text first becomes bytes

Base64 has no idea what a letter is. It takes a sequence of bytes and rewrites it with 64 printable characters. When you type text into the encoder, something has to turn characters into bytes first, and this tool uses UTF-8 for that step. For plain ASCII letters the answer is simple, since each letter is one byte with the same value it has in ASCII. For anything beyond that range, UTF-8 uses longer sequences. The practical effect is that the number of letters you see on screen and the number of bytes that get encoded are two separate counts, and the second one decides how long the Base64 string will be.

What UTF-8 does to é

The letter é is the Unicode code point U+00E9, which is 233 in decimal. UTF-8 stores code points from U+0080 to U+07FF in two bytes, with the pattern 110xxxxx 10xxxxxx. The eleven data bits of 233 are 00011101001, which split into 00011 and 101001. Placed in the pattern, they give 11000011 and 10101001, hexadecimal C3 and A9. The UTF-8 converter in the first case returns exactly C3 A9. Two bytes enter the next stage, where a single byte would have entered for the ASCII letter e. Codes at or below U+007F use one byte, and the Unicode Standard and RFC 3629 define the byte ranges used by the longer forms.

From the two bytes to w6k=

Base64 reads three bytes at a time, and here there are two, so the group is short. The sixteen bits 11000011 10101001 are cut into six-bit pieces: 110000, 111010, 1001 and two zero bits added to complete the last piece, 100100. In decimal, those pieces are 48, 58 and 36. In the standard alphabet, 48 is the letter w, 58 is the digit 6 and 36 is the letter k. One equals sign fills the group to four characters, so the encoded text is w6k=. The second case encodes é and returns that string. The final character k carries the two zero pad bits, which a canonical encoding always sets to zero.

Decoding back to the letter

The third case decodes w6k= and returns é. The decoder removes the equals sign, converts the characters back to six-bit values, rebuilds the bytes C3 and A9 and then reads them as UTF-8. Two stages are involved, and either can fail. A value that fails the first stage has a problem with its alphabet, padding or pad bits. A value that passes the first stage but fails the second contains bytes that are not valid UTF-8 text, a situation covered in another guide. In this case both stages succeed and the original single character comes back, which makes a round trip a convenient quick test for any short string.

A comparison that goes wrong without UTF-8

Two people can encode the same visible word and get different Base64 because they used different byte encodings. In the Latin-1 character set, still common in older systems, é is the single byte E9, and its Base64 form is 6Q==, not w6k=. In UTF-16 it would be two bytes of a different pattern, 00 E9 or E9 00 depending on byte order. A comparison script that reads one value as Latin-1 and the other as UTF-8 will report a mismatch for a perfectly good letter. This tool states that it uses UTF-8, so the result here corresponds to the UTF-8 convention that most web and API systems follow.

How length grows with non-ASCII text

A string of n ASCII letters encodes to 4 times the ceiling of n over 3 characters. The word cafe has four bytes and encodes to Y2FmZQ==, eight characters. The word café has five bytes, because é takes two, and its Base64 form is Y2Fmw6k=, again eight characters. In general, the encoded size depends on the byte count, so text in alphabets that need two or three bytes per letter produces longer output for the same number of letters. When a field limit is given in encoded characters, work backwards from bytes to letters instead of assuming one byte per letter. The UTF-8 byte counter on this site helps with that planning.

Precomposed and decomposed forms differ

Some accented letters can be written in two ways. The precomposed é is the single code point U+00E9. The decomposed form is the letter e followed by the combining acute accent U+0301. Both display as é, but the decomposed form has three UTF-8 bytes, 65 CC 81, and a different Base64 value. A text that looks identical may therefore encode differently depending on how it was typed or which software normalized it. This guide uses the precomposed letter. When a comparison fails for text that looks the same, inspecting the code points and bytes is the way to see which form each side holds.

Three-byte and four-byte characters

The same method extends to larger code points. Characters from U+0800 to U+FFFF take three bytes in UTF-8, as the euro sign U+20AC does with the bytes E2 82 AC, which is 4oKs in Base64. Characters from U+10000 upward take four bytes, such as the grinning face U+1F600 with F0 9F 98 80. Because Base64 handles three bytes at a time, a three-byte character such as the euro sign fills a group exactly and needs no equals sign, while the two-byte é and the four-byte emoji leave a short final group. The padding of the encoded text is a sign of the byte count, and not of the number of letters.

Using the inspection controls in practice

When two encoded values disagree, work from the left. First compare the original text in a plain text view, then look at its UTF-8 bytes with the byte converter, and only then compare the Base64 strings. The bytes are the earliest point at which two systems can diverge in a way that Base64 will faithfully preserve. Keep the exact text with any value you save, since an apparently equal text typed on another keyboard layout or pasted from a document may use a different code point. These checks work for a single character here and scale to longer strings with the same steps. Write down the character, its code point, its UTF-8 bytes and the Base64 value together, as this guide does for é, and a later reader can retrace the work.

Reproduce the checks

UTF-8 bytes

Open the Utf8 Byte Converter and enter:

Calculation mode
encode
Text or encoded input
é

Expected output:

Hex

C3 A9

Two bytes feed the next representation.

Base64 form

Open the Base64 Encoder Decoder and enter:

Calculation mode
encode
Text or encoded input
é

Expected output:

Text

w6k=

The encoded value represents those UTF-8 bytes.

Text round trip

Open the Base64 Encoder Decoder and enter:

Calculation mode
decode
Text or encoded input
w6k=

Expected output:

Text

é

The original scalar is recovered.

References and implementation scope

The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.

Sources

Related tasks