JSONHint

Preparing your workspace…

Base64 Encoding Explained

A full technical breakdown of what Base64 is, how it transforms binary data into text, and when you should (and shouldn't) use it in software.

JH
JSONHint
By JSONHint · Practical guide

Solving the ASCII Problem

Computer networks, databases, and older protocols (like SMTP for email) were historically designed to handle and transmit basic text characters (the ASCII standard: letters, numbers, and basic punctuation). These text-only protocols immediately choke when you attempt to send raw binary data (like a raw .png image, an encrypted payload, or a compiled executable).

Base64 encoding is the universal solution to this problem. It is a mathematical process that takes any raw binary data and transforms it into a safe, ASCII-compatible text string.

How Does the Translation Work?

The name "Base64" refers to the fact that the resulting text uses exactly 64 distinct visual characters:

  • Uppercase letters: A-Z (26 characters)
  • Lowercase letters: a-z (26 characters)
  • Numbers: 0-9 (10 characters)
  • Symbols: + and / (2 characters)

Under the hood, a computer processes everything in 8-bit increments (Bytes). Base64 works by taking three 8-bit bytes (24 bits total), slicing those 24 bits into four 6-bit chunks, and translating each 6-bit chunk directly into one of the 64 safe characters listed above.

The Data Tradeoff

Because Base64 turns 3 bytes of binary data into 4 bytes of text characters, Base64 encoding always increases the size of your data by ~33%. Therefore, you should never encode data just for fun; only encode it when the transport protocol mandates text-only data.

Base64 Padding (The Equals Sign =)

You will frequently notice that Base64 strings end with one or two equals signs (= or ==). Because the Base64 algorithm requires data in groups of 3 bytes, if the original data file didn't perfectly divide by 3, the algorithm "pads" the end of the text with equals signs to make up the missing bytes.

Common Misconception: Base64 is NOT Encryption

A dangerous mistake junior developers make is looking at a scrambled Base64 string (like cGFzc3dvcmQxMjM=) and assuming the data is encrypted and secure.

Base64 provides absolutely zero security. It is purely an encoding algorithm, which means there is no secret key. Anyone in the world with a web browser or a terminal can instantly decode a Base64 string back into the original data. If you encode a password in Base64 and send it over an unencrypted HTTP connection, you have securely protected nothing.

Real World Uses

  • Email (MIME): Email clients use Base64 to convert file attachments into text so they can be securely mailed by the SMTP server.
  • Data URIs: Web developers can encode small icons into Base64 and embed them directly inside HTML <img src="data:image/png;base64,..."> or CSS files to avoid making an extra network request for the image.
  • JSON Web Tokens: The Header and Payload of a JWT are actually just Base64Url encoded JSON strings.

Encode and Decode Safely

Need to quickly encode a text string into Base64, or decode an obscure string you found in a configuration file? Use our free encoder.

Open Base64 Converter