Skip to content
uencoder

Base64

Base64 maps arbitrary binary data onto 64 printable ASCII characters (A-Z, a-z, 0-9, +, /) so that binary data can travel over text-only channels.

Purpose

It solved the problem of early mail systems that could carry only 7-bit ASCII text and could not transport binary attachments directly, while keeping control characters from being mangled by gateways.

Mechanism

The input byte stream is processed in 3-byte (24-bit) groups split into four 6-bit units, each mapped to one character of the Base64 alphabet. A final short group is padded with = to 4 characters. The encoded length is about 4/3 of the input, and the output length is always a multiple of 4.

Use cases

  • Embedding binary data in JSON, XML, and URLs (e.g., small images in Data URLs)
  • MIME attachment transport in email
  • Encoding username:password in HTTP Basic authentication
  • Encoding the header and payload segments of a JWT

Examples

  • Input
    Hello
    Output
    SGVsbG8=

    5 bytes to 8 characters with one trailing = pad

Common errors

Using standard Base64 directly in URLs, where + and / get percent-encoded and decoding fails
Use Base64URL instead (- and _ replace + and /, and = padding is dropped)

Related terms

Related tools

Related tutorials

References