Text Conversion

Text Encoding Explained: Base64, URL Encoding, Binary, and More

Understand text encoding formats including Base64, URL encoding, binary, hex, and ASCII. Learn when to use each encoding and how they work.

Text encoding is the process of converting text into a specific format for transmission or storage. Different encoding formats serve different purposes — from safely transmitting data in URLs to storing binary data as text. Understanding encoding is essential for developers, webmasters, and anyone working with digital text.

What Is Text Encoding?

Computers store data as numbers. Text encoding defines how characters (letters, numbers, symbols) map to numeric values. The most fundamental encoding is ASCII, which assigns a number (0–127) to each character. For example, 'A' = 65, 'B' = 66, 'a' = 97.

Modern systems use Unicode (UTF-8), which supports over 1 million characters including emoji, Chinese characters, Arabic script, and more. UTF-8 is backward-compatible with ASCII.

Base64 Encoding

Base64 encoding converts binary data into a text string using 64 characters (A-Z, a-z, 0-9, +, /). It's commonly used to:

  • Embed images in CSS or HTML (data URIs)
  • Encode email attachments (MIME)
  • Transmit binary data over text protocols
  • Store complex data in JSON or XML

Base64 increases data size by about 33%. A 3-byte binary sequence becomes 4 text characters. While this overhead is significant, Base64 ensures data survives transmission through systems that only handle text.

URL Encoding

URL encoding (also called percent-encoding) converts special characters into a format safe for URLs. Characters like spaces, ampersands, and non-ASCII characters are replaced with % followed by two hex digits.

For example:

  • Space becomes %20
  • & becomes %26
  • + becomes %2B
  • Chinese characters become sequences like %E4%BD%A0%E5%A5%BD

URL encoding is essential for:

  • Building query strings with special characters
  • Ensuring URLs work across all browsers and servers
  • Preventing injection attacks through URL parameters

Binary Encoding

Binary encoding represents each character as an 8-bit binary number (a sequence of 0s and 1s). For example, 'H' = 01001000, 'e' = 01100101.

Binary is the fundamental language of computers. Understanding binary encoding helps with:

  • Debugging low-level data issues
  • Understanding how computers store text
  • Working with network protocols
  • Learning computer science fundamentals

Hexadecimal Encoding

Hexadecimal (hex) encoding represents each character as a two-digit hex number. For example, 'H' = 48, 'e' = 65, 'l' = 6C.

Hex is more compact than binary (2 digits vs 8) and is widely used in:

  • Color codes in CSS (#FF5733)
  • Memory addresses in debugging
  • Character encoding tables
  • Cryptographic hash values

ASCII Codes

ASCII codes are the numeric values assigned to characters in the ASCII table. The ASCII table defines 128 characters (0–127), including:

  • 0–31: Control characters (newline, tab, etc.)
  • 32–126: Printable characters (letters, numbers, punctuation)
  • 65–90: Uppercase letters (A–Z)
  • 97–122: Lowercase letters (a–z)
  • 48–57: Digits (0–9)

Comparison of Encoding Formats

FormatOutput ExampleSize IncreaseCommon Use
Base64SGVsbG8=+33%Email, data URIs
URL EncodingHello%20WorldVariableURLs, query strings
Binary01001000 011001018xLow-level computing
Hexadecimal48 65 6C 6C 6F2xColors, debugging
ASCII72 101 108 108 1113xCharacter mapping

Frequently Asked Questions

What is the difference between encoding and encryption?
Encoding transforms data into a different format for compatibility, not security. Anyone can decode Base64 or URL encoding. Encryption transforms data to protect it from unauthorized access, requiring a key to decrypt.
Can Base64 be decoded back to the original text?
Yes. Base64 is a reversible encoding. Use a Base64 Decode tool to convert Base64 back to the original text or binary data.
Why do URLs need encoding?
URLs can only contain a limited set of characters (letters, numbers, and a few special characters). Spaces, non-ASCII characters, and certain symbols must be encoded to be transmitted safely over the internet.
Is UTF-8 the same as ASCII?
UTF-8 is backward-compatible with ASCII. The first 128 characters of UTF-8 are identical to ASCII. UTF-8 extends beyond ASCII to support over 1 million additional characters including emoji and non-Latin scripts.