What is Base64?

Published

Base64 is a method for writing any binary data using only 64 safe, printable characters: the uppercase letters A–Z, the lowercase letters a–z, the digits 0–9, and two symbols, normally + and /. A 65th character, =, is used for padding at the end.

Why do we need it?

Computers store everything as bytes, and a byte can have 256 different values. Many systems, however, were designed to carry text only:

  • E-mail (SMTP) was built for 7-bit ASCII text with limited line lengths.
  • JSON and XML documents cannot contain raw binary bytes.
  • URLs, HTTP headers and cookies only allow a restricted set of characters.
  • Copy and paste, terminals and chat apps may change line endings or drop invisible characters.

If you push raw image bytes through such a channel, some bytes get changed or removed and the file breaks. Base64 solves this by translating bytes into characters that every system passes through unchanged.

How does it work, in one paragraph?

Base64 reads the input three bytes (24 bits) at a time and splits those 24 bits into four groups of 6 bits. Each 6-bit group is a number from 0 to 63, which is replaced by the character at that position in the Base64 alphabet. So 3 bytes always become 4 characters. If the input length is not divisible by 3, the last group is filled up and marked with =. The full details are in the algorithm guide.

Text Bytes (hex) Base64
Man 4D 61 6E TWFu
Ma 4D 61 TWE=
M 4D TQ==

Where is Base64 used?

  • E-mail attachments (MIME): every file you attach is Base64-encoded.
  • Data URIs: images and fonts embedded directly in HTML and CSS — data:image/png;base64,... (learn more).
  • APIs: sending files or binary hashes inside JSON.
  • Authentication: HTTP Basic auth headers and JSON Web Tokens.
  • Certificates and keys: PEM files (-----BEGIN CERTIFICATE-----).
  • Kubernetes secrets, environment variables, QR codes, and many more.

The 33% overhead

Because 3 bytes become 4 characters, Base64 data is about 33% larger than the original (plus padding, and line breaks in MIME). A 3 MB photo becomes roughly 4 MB of Base64 text. Compression such as gzip recovers most of this on the network — see Base64 and gzip.

Base64 is not encryption

This is the most important point: anyone can decode Base64. It has no key and no secret. cGFzc3dvcmQ= is simply password. Never use Base64 to “hide” credentials. We explain this in detail in Base64 encryption is a lie.

Try it

Encode any text with the text to Base64 encoder, or decode a value with the Base64 decoder.

Comments (0)

Questions, ideas or a bug in “What is Base64?”? Leave a comment, rate the tool, or reply to others.

No comments yet. Be the first to share your feedback!

Leave a comment

Rate this tool:
Esc
↑ ↓ move↵ openEsc close