Text Encoding Converter

Convert text between UTF-8, Base64, hex, binary, URL encoding, HTML entities and \u escapes. Emoji and accents survive the round trip intact.

The interactive tool loads here when JavaScript runs.

About this tool

What is the Text Encoding Converter?

The Text Encoding Converter turns text from one representation into another: plain UTF-8 text, ASCII, Base64, hexadecimal, binary, URL (percent) encoding, HTML entities and JavaScript-style Unicode escapes. Pick From Encoding and To Encoding, paste your input and click Convert Text.

Every byte-based format (Base64, hex and binary) works on the UTF-8 bytes of the text, which is what servers, files and APIs actually exchange. So café becomes 636166c3a9 in hex and Y2Fmw6k= in Base64, and decoding gives café back. If decoded bytes are not valid UTF-8, the converter says so instead of filling the output with replacement characters.

It does not transcode between legacy code pages such as Windows-1252, Shift JIS or UTF-16 files. Use it to inspect and convert text, and use a tool like iconv when you need to re-encode a whole file.

  • Eight representations: UTF-8, ASCII, Base64, hex, binary, URL, HTML entities and Unicode escapes
  • Byte formats use UTF-8, so non-Latin text and emoji round-trip
  • Surrogate pairs and \u{...} escapes handled correctly
  • Clear errors for invalid Base64, odd hex and non-UTF-8 bytes
  • Runs in your browser; input is not sent anywhere
Read the guide: UTF-8, Mojibake and Byte Order Marks: Text Encoding for Developers

Updated

How to use the Text Encoding Converter

  1. Choose the format your input is in under From Encoding. Use UTF-8 for ordinary text.
  2. Choose the format you want under To Encoding.
  3. Paste your input into Input Text and click Convert Text. Errors such as invalid Base64 or bytes that are not UTF-8 appear as a message.
  4. Copy the Output Text, or click the swap button to reverse the direction and convert the result back.

Worked examples

One string, several encodings

Input

café ☕ (From: UTF-8)

Output

Base64: Y2Fmw6kg4piV
Hex: 636166c3a920e29895
URL: caf%C3%A9%20%E2%98%95
Unicode escape: caf\u00e9 \u2615

Six characters become nine UTF-8 bytes: é takes two and the coffee cup three. Every byte-based output reflects those nine bytes.

Catching a Latin-1 Base64 string

Input

Y2Fm6Q== (From: Base64, To: UTF-8)

Output

Error: The Base64 input decodes to bytes that are not valid UTF-8

This is café encoded from Latin-1, where é is the single byte E9. E9 on its own is not valid UTF-8, so the converter reports it instead of printing caf�.

Background and insight

Text on a computer is two layers: characters (Unicode code points such as U+00E9 for é) and the bytes used to store them. UTF-8, designed by Ken Thompson and Rob Pike in 1992 and standardized in RFC 3629, stores ASCII as one byte and everything else as two to four bytes. It is now the default encoding of the web, JSON and most source code.

JavaScript strings are UTF-16 internally, which is where many encoding bugs start. Characters outside the Basic Multilingual Plane, such as most emoji, take two UTF-16 code units called a surrogate pair. 😀 is U+1F600, stored as \ud83d\ude00. Code that walks a string one code unit at a time and escapes only the first half silently destroys the character; this converter escapes both halves and decodes \u{1F600} as well.

The classic symptom of an encoding mismatch is mojibake: UTF-8 bytes read as Latin-1 or Windows-1252. é is C3 A9 in UTF-8, and when each byte is read as a separate Latin-1 character you see é. A byte order mark (EF BB BF) at the start of a file is another frequent culprit; the converter keeps it as U+FEFF so you can see it rather than dropping it silently.

Common use cases

  • Debugging garbled text

    Convert a suspicious string to hex to see whether é is stored as C3 A9 (UTF-8) or E9 (Latin-1).

  • Preparing escaped strings

    Turn text with accents or emoji into \u escapes for a JSON fixture, a Java properties file or JavaScript source that must stay ASCII.

  • Reading encoded payloads

    Decode a Base64 or percent-encoded value from a log, cookie or query string to readable text.

  • Teaching how encodings work

    Show the binary of each UTF-8 byte to explain the 110xxxxx and 10xxxxxx bit patterns of multi-byte characters.

Tips and limitations

  • Base64 input may use the URL-safe alphabet (- and _) and may omit = padding; both are accepted.
  • Hex and binary input can contain spaces. Binary must be a whole number of 8-bit groups.
  • URL decoding treats + literally. Form-encoded data that uses + for spaces needs the plus signs replaced first.
  • The ASCII output replaces each non-ASCII character with one question mark, matching what many legacy systems do.
  • HTML encoding escapes only & < > " and '. Other characters stay as they are, which is correct for UTF-8 pages.

Sources and further reading

  1. RFC 3629: UTF-8, a transformation format of ISO 10646, Internet Engineering Task Force. The UTF-8 standard, one to four bytes per code point
  2. UTF-8 history, University of Cambridge Computer Laboratory. Rob Pike's account of how he and Ken Thompson designed UTF-8 in 1992
  3. FAQ: UTF-8, UTF-16, UTF-32 and BOM, Unicode Consortium. Surrogate pairs and the byte order mark
  4. Encoding Standard, WHATWG. How browsers decode UTF-8 and treat the latin1 label as windows-1252
  5. String, MDN Web Docs. JavaScript strings as UTF-16 code units, and surrogate pairs

Frequently asked questions

Why does Base64 of an accented word differ from other tools?

This converter Base64-encodes the UTF-8 bytes, so é becomes two bytes, C3 A9, and café becomes Y2Fmw6k=. Tools that use the browser's btoa directly treat each character as one Latin-1 byte and produce Y2Fm6Q==, or fail outright on characters such as € that Latin-1 lacks.

How do I convert an emoji to a \u escape sequence?

Set From to UTF-8 and To to Unicode Escape. Emoji outside the Basic Multilingual Plane become two escapes, a surrogate pair, because that is how JavaScript and JSON represent them: 😀 becomes \ud83d\ude00. Decoding accepts that form and the \u{1F600} form.

What does "not valid UTF-8" mean when decoding hex or Base64?

The bytes break UTF-8's rules, for example a lead byte such as C3 followed by a byte that is not a continuation byte, or a lone byte above 7F. The data was probably written in another encoding such as Latin-1 or Windows-1252, or it is binary rather than text.

Why do I see é instead of é?

That is UTF-8 read as Latin-1 or Windows-1252. é is stored as the two bytes C3 A9, and a decoder that assumes one byte per character shows them as à and ©. Fix it at the source by declaring the charset as UTF-8 rather than converting the garbled text.

Does this converter keep a byte order mark?

Yes. When hex or Base64 input starts with the UTF-8 BOM EF BB BF, it is kept as the character U+FEFF, which shows as \ufeff in Unicode Escape output. Dropping it silently would hide the reason a parser rejects the first field of a file.

Can it convert files between UTF-16 and UTF-8?

No. It converts pasted text between representations and uses UTF-8 for all byte formats. To re-encode a UTF-16 or Windows-1252 file, use iconv, for example iconv -f UTF-16 -t UTF-8 in.txt > out.txt, or your editor's save-with-encoding option.

Is there an in-depth guide to the Text Encoding Converter?

Yes. “UTF-8, Mojibake and Byte Order Marks: Text Encoding for Developers” covers the background, how it works, common pitfalls and worked examples. Read the full guide.