Skip to content
ZeroServer.tools

UTF-8 Encoder

Encode text into UTF-8 byte values.

Format
UTF-8 Bytes

Understanding UTF-8 Byte Encoding

UTF-8 is the dominant text encoding on the web. ASCII characters take a single byte, while accented letters, symbols, and emoji span two to four bytes. This tool encodes your text to its raw UTF-8 bytes and shows them as hexadecimal or decimal — useful for debugging encoding issues, building byte arrays, or inspecting how multi-byte characters are stored. Pairs with the UTF-8 Decoder. Runs entirely in your browser.

Built and maintained by Meet Shah · Last updated

What this tool is used for

  • Producing the exact byte sequence for a string so you can compare it against what a parser or hash function received.
  • Working out how many bytes a field will occupy when the limit is in bytes and the content is not ASCII.
  • Building a test fixture that deliberately exercises one, two, three and four byte characters.
  • Checking whether two strings that look identical are actually the same bytes before blaming a comparison.
  • Preparing a hex byte sequence for a protocol that specifies its encoding explicitly.

How it works in practice

A worked example

A product name will not save correctly in a MySQL column declared utf8, which MySQL 8.4 treats as a deprecated alias for utf8mb3, so the developer encodes the name to find which characters need four bytes before moving the column to utf8mb4.

Input
Text    Crème brûlée — gift box 🎁
Format  Hex (4A), the default
Output
43 72 C3 A8 6D 65 20 62 72 C3 BB 6C C3 A9 65 20 E2 80 94 20 67 69 66 74 20 62 6F 78 20 F0 9F 8E 81

The 25 characters became 33 bytes. Each byte below 80 is plain ASCII and stands alone; C3 opens the two-byte forms of è, û and é, E2 opens the three-byte em dash (E2 80 94), and F0 opens the four-byte gift emoji (F0 9F 8E 81), because in UTF-8 the first byte of a sequence announces its length and every byte after it falls between 80 and BF. MySQL's utf8mb3 stores at most three bytes per character, so the emoji is the only part of this name it cannot hold, while the accented letters and the em dash fit. In the hex view, any byte from F0 to F4 marks the start of a character that needs utf8mb4.

The edge case that catches people

A line break pasted from a Windows text file comes out as 0A, not 0D 0A. The box is a textarea, and a textarea's value reports every CR LF pair, and every lone CR, as a single LF; that normalised value is the string the page passes to TextEncoder. The web-platform tests assert this behaviour, and Chromium applies it to typed and pasted text alike. So for multi-line text the bytes listed here are one fewer per line break than the CRLF file holds, and a byte limit checked against this output can pass here and still fail on the real file.

When not to use this tool

This page encodes text after the browser has already decoded it and normalised its line breaks, so it cannot show the bytes a file or a database actually holds: a Latin-1 file that your editor displays correctly pastes in exactly like its UTF-8 equivalent, and CRLF endings arrive as LF. To see stored bytes, ask the store itself. MySQL's HEX() applied to the column returns each byte as two hexadecimal digits, and a hex dump of the file shows its line endings as written. The page also keeps no running byte count, so when a limit is in bytes, count the space-separated values in the output.

Frequently Asked Questions

How many bytes does a character take?
One to four. ASCII stays at one byte, most Latin/Greek/Cyrillic take two, most CJK and the rest of the Basic Multilingual Plane take three, and emoji and rare scripts take four.
Why did UTF-8 win over UTF-16 and UTF-32?
Backward compatibility and self-synchronisation. ASCII files are already valid UTF-8, and because continuation bytes always start 10, a decoder that starts mid-stream can find the next character boundary — neither property holds for UTF-16.
What is an overlong encoding?
Encoding a character in more bytes than necessary, such as writing / as C0 AF instead of 2F. It is forbidden because it was a real security hole — path filters checking for the short form missed the long one and allowed directory traversal.
Why is my string length wrong?
Because the unit differs by language. JavaScript's .length counts UTF-16 code units and charges most emoji 2; Python 3 counts code points; a byte length counts UTF-8 bytes. For user-visible characters you need grapheme clusters, which is a fourth number.
Should I write a BOM?
No. UTF-8 has no byte order, so the mark is redundant, and it breaks shebang lines, PHP output and naive CSV parsers, which read it into the first header. Some Windows tools still add it, so a file can begin with the bytes EF BB BF. The exception is a CSV for Excel, which assumes a legacy code page without it.
Why are surrogate code points not encodable?
Because U+D800–U+DFFF exist only to let UTF-16 reach the higher planes, and mean nothing as characters. Writing them as three-byte sequences gives CESU-8 or WTF-8, not UTF-8, so a strict encoder refuses them. This page's TextEncoder swaps a lone one for U+FFFD, the replacement character, and writes EF BF BD.
What is normalisation and why does it matter before encoding?
The same visible text can be several code point sequences — é as one character or e plus a combining accent. They encode to different bytes, so comparison, hashing and deduplication all need a normalisation form chosen first.

Common errors and gotchas

  • Assuming a character is one byte. Accented letters take two, most CJK three and emoji four, which is where byte limits break.
  • Comparing strings that look the same but are normalised differently. Composed and decomposed forms encode to different bytes.
  • Writing a byte-order mark into UTF-8 output. It is permitted, almost never wanted, and it breaks naive parsers.
  • Trying to encode a lone surrogate. Those code points exist only inside UTF-16 and have no valid UTF-8 representation.
  • Producing an overlong encoding by padding a short character into more bytes. It decodes, but it is invalid and rejected as a security risk.

Related Encoders & Decoders tools

Private & free — this tool runs entirely in your browser.

IndieKit — Ship your Next.js startup in days.affiliate