Character Encoding Guide
What is Character Encoding?
Character encoding defines how characters (letters, symbols, emoji) are represented as bytes. Choosing the right encoding prevents garbled text, broken data, and security vulnerabilities in web applications.
Common Encodings
- ASCII: 7-bit, 128 characters (English letters, digits, symbols). The foundation of most encodings.
- UTF-8: Variable-width (1-4 bytes), backward-compatible with ASCII. The web standard, used by 98%+ of websites.
- UTF-16: 2 or 4 bytes per character. Used internally by JavaScript and Windows.
- Latin-1 (ISO 8859-1): 8-bit, covers Western European characters.
HTML Entity Encoding
HTML entities represent special characters that have meaning in HTML syntax. Escaping prevents rendering issues and XSS attacks.
< → < > → > & → & " → " ' → ' 😀 → 😀
Hex Encoding
Hex encoding represents each byte as two hexadecimal characters. Used in debugging, binary protocols, and color codes.
"Hello" → 48656c6c6f
"ABC" → 414243
// JavaScript
Buffer.from("Hello").toString("hex") // "48656c6c6f"
Buffer.from("48656c6c6f", "hex").toString() // "Hello"Base32 Encoding
Base32 uses 32 characters (A-Z, 2-7) to encode binary data. It's case-insensitive and avoids ambiguous characters, making it ideal for TOTP secrets, file names, and human-readable tokens.
Common Mistakes
- Not specifying encoding: always declare
<meta charset="UTF-8">in HTML. - Mixing encodings: reading a UTF-8 file as Latin-1 produces mojibake (garbled text).
- Not escaping user input: unescaped HTML in user content leads to XSS vulnerabilities.
- Double-encoding: encoding an already-encoded string produces broken output like
&lt;.
Use our HTML Escape, Hex Codec, and Base32 Codec tools to encode and decode text.
FAQ
Should I always use UTF-8?
Yes, for virtually all modern web development. UTF-8 supports all Unicode characters and is the universal standard.
What causes mojibake (garbled text)?
Mojibake happens when text is decoded with a different encoding than it was encoded with. Ensure consistent UTF-8 across your entire stack.