What is Base64 Encoding? How It Works

May 26, 20266 min read

What is Base64?

Base64 is a binary-to-text encoding scheme that represents binary data using a set of 64 printable ASCII characters. It converts binary data into a string of letters, numbers, and two special characters (+ and /).

How Base64 Works

Base64 takes 3 bytes (24 bits) of binary data and splits them into four 6-bit groups. Each 6-bit group maps to one of 64 characters in the Base64 alphabet:

Value 0–25:  A–Z
Value 26–51: a–z
Value 52–61: 0–9
Value 62:    +
Value 63:    /

Example

The text "Hello" encodes to:

Hello → SGVsbG8=

The = padding character appears when the input length is not a multiple of 3 bytes.

When to Use Base64

  • Email attachments: MIME encodes binary files as Base64
  • Data URLs: Embed small images directly in HTML/CSS
  • API authentication: HTTP Basic Auth sends credentials as Base64
  • JSON web tokens: JWT payloads are Base64-encoded

When NOT to Use Base64

  • Large files: Base64 increases size by ~33%
  • Password storage: Base64 is encoding, not encryption — never use it for passwords
  • Compression: Base64 does not compress data

Try It Yourself

Use our free Base64 Encoder/Decoder to encode and decode Base64 strings online.