Back to Blog
Digital data streams and binary encoding visualization
Developer Tools
base64
encoding
developer tools
web development
JWT

Base64 Encoding Demystified: What Every Developer Needs to Know

A practical deep-dive into Base64 encoding — how it works, why it's used, and how to encode/decode data properly. Includes real-world use cases like data URLs, JWT tokens, and API authentication.

txt.tools Team 2024-02-20 8 min read

What Is Base64 Encoding?

Base64 is a binary-to-text encoding scheme that converts binary data into an ASCII string format. It's not encryption (a common misconception) — it's encoding. Anyone can decode Base64 without a key.

The name "Base64" comes from the fact that it uses 64 different characters (A-Z, a-z, 0-9, +, /) plus the = padding character to represent binary data.

How Base64 Actually Works

Base64 processes data in 3-byte chunks:

  • Take 3 bytes of binary data (24 bits)
  • Split into 4 groups of 6 bits each
  • Convert each 6-bit value (0-63) to a Base64 character
  • If the input isn't divisible by 3, add = padding
  • Example:

    The text "Man" converts to "TWFu" in Base64.

    | Text | M | a | n |

    |------|---|---|---|

    | ASCII | 77 | 97 | 110 |
    | Binary | 01001101 | 01100001 | 01101110 |
    | 6-bit groups | 010011 | 010110 | 000101 | 101110 |
    | Base64 | T | W | F | u |

    Common Use Cases

    1. Data URLs

    Embed images directly in HTML/CSS:

    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...">

    2. Email Attachments (MIME)

    Email protocols are text-based. Base64 encodes binary attachments for transmission.

    3. API Authentication

    Basic Auth headers use Base64:

    Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

    4. JWT Tokens

    JSON Web Tokens use Base64URL (a URL-safe variant) for their header and payload sections.

    5. Storing Binary Data in JSON

    JSON has no native binary type. Base64 encodes binary data as a string.

    Important Security Note

    **Base64 is NOT encryption.** Never use it to protect sensitive data:

  • Base64 is easily decoded by anyone
  • It provides no confidentiality
  • It provides no integrity checking
  • Use proper encryption (AES, RSA) for sensitive data
  • Base64 vs Base64URL

    Standard Base64 uses "+" and "/" characters that need URL-encoding in URLs. Base64URL replaces them with "-" and "_" respectively, making it safe for URLs without additional encoding.

    Using Our Tools

    Visit txt.tools for free Base64 encoding and decoding:

  • **Base64 Encode**: Convert text to Base64
  • **Base64 Decode**: Convert Base64 back to text
  • **URL Encode/Decode**: For URL-safe encoding needs
  • All processing happens in your browser. Your data stays private.

    Performance Considerations

    Base64 encoding increases data size by approximately 33%. This means:

  • A 1MB image becomes ~1.37MB in Base64
  • Network transfer takes longer
  • Use Base64 for small payloads, not large files
  • For large files, consider blob URLs instead
  • Advertisement

    Enjoyed this article?

    Check out our free online tools at txt.tools to help you work faster and smarter.