How to use the text byte layout inspector
- Type or paste your text.
- Choose an encoding: UTF-8, or UTF-16 or UTF-32 in little or big endian.
- Tick Start with a byte order mark if you want the mark at the front.
- Read the total bytes, the code points and the table of bytes for each character.
Formula
UTF-8: 1 byte below U+0080, 2 below U+0800, 3 below U+10000, 4 above
UTF-16: one 16 bit unit below U+10000, otherwise a surrogate pair
surrogate pair: high = 0xD800 + ((cp - 0x10000) >> 10), low = 0xDC00 + ((cp - 0x10000) & 0x3FF)
UTF-32: always 4 bytes per code point
A byte order mark is the code point U+FEFF written in the chosen encoding: EF BB BF in UTF-8, FE FF in UTF-16 big endian and FF FE in UTF-16 little endian.
Four characters, four lengths
The text Aé€😀 has four code points. In UTF-8 they take 1, 2, 3 and 4 bytes, 41, c3 a9, e2 82 ac and f0 9f 98 80, which is 10 bytes. In UTF-16 big endian the first three take 2 bytes each (00 41, 00 e9, 20 ac) and the emoji takes a surrogate pair, d8 3d de 00, so the total is 10 bytes, or 12 with the byte order mark fe ff.
In UTF-32 little endian every code point takes 4 bytes, so the text is 16 bytes. The emoji, code point U+1F600, is the bytes 00 f6 01 00. In UTF-16 the text has 5 code units because the emoji needs two.
Characters, code points and bytes
A character you see can be one code point or several, and a code point can take one to four bytes depending on the encoding. That is why a text length in characters is not its size in bytes. Limits on database fields, messages and file names are usually in bytes, so a short text with emoji can be longer than it looks.
The byte order mark is optional in UTF-8 and is often left out. UTF-16 and UTF-32 files usually start with one so readers know the byte order. Lone surrogates, which are not valid text, are shown as the replacement character U+FFFD.
Related tools
To check a text against a byte limit, use the Text Byte Size Calculator. To see how normalization changes the code points, use the Unicode Normalization Comparer. To open a file as bytes, use the Hex Viewer, and to repair garbled accents, use the Text Encoding Fixer.
Assumptions and limits
- Text is limited to 20,000 characters, and the table shows the first 300 code points.
- Line breaks from the text box are counted as a single line feed.
- A code point is shown as U+ and at least four hex digits.
- Invalid sequences cannot occur in text typed here. Lone surrogates are replaced.
- The text shown when the page opens is an example.
Frequently asked questions
Why does an emoji take two UTF-16 units?
UTF-16 units are 16 bits wide, which covers code points up to U+FFFF. Higher code points, such as most emoji, use a pair of units called a surrogate pair.
What is a byte order mark?
It is the character U+FEFF placed at the start of a file. Readers use how it appears in the bytes to tell little endian from big endian.
Why can the byte count differ from the character count?
Most characters outside basic ASCII take two to four bytes in UTF-8. Counting characters and counting bytes only agree for plain ASCII text.
Does the page change my text?
No. It reads the code points of the text and shows the bytes an encoder would write. Nothing is sent anywhere.