What is Base64?

Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format by translating it into a radix-64 representation. It uses 64 printable characters (A-Z, a-z, 0-9, +, /) to encode binary data.

Quick Facts

Full NameBase64 Encoding
Created1987 (Privacy Enhanced Mail specification)
SpecificationOfficial Specification

How It Works

Base64 encoding works by taking three bytes (24 bits) of binary data and converting them into four ASCII characters. Each character represents 6 bits of the original data. If the input length is not divisible by 3, padding characters (=) are added to make the output length a multiple of 4. This encoding increases the data size by approximately 33% but ensures the data can be safely transmitted through systems that only support ASCII text. Base64URL is a URL-safe variant that replaces '+' with '-' and '/' with '_', and omits padding '=' characters. This variant is essential for JWT tokens, URL parameters, and filenames where standard Base64 characters would cause issues.

Key Characteristics

  • Uses 64 printable ASCII characters for encoding
  • Output is approximately 33% larger than input
  • Padding with '=' characters when input length is not divisible by 3
  • URL-safe variant uses '-' and '_' instead of '+' and '/'
  • Reversible encoding - can be decoded back to original binary
  • Not encryption - provides no security, only encoding

Common Use Cases

  1. Embedding images in HTML/CSS using data URIs
  2. Encoding email attachments (MIME)
  3. Storing binary data in JSON or XML
  4. Encoding authentication credentials in HTTP Basic Auth
  5. Transmitting binary data through text-only protocols

Example

loading...
Loading code...

Frequently Asked Questions

Is Base64 encoding the same as encryption?

No, Base64 is not encryption. It is simply an encoding scheme that converts binary data to text format. Anyone can decode Base64 data without a key. For security, use proper encryption algorithms like AES.

Why does Base64 increase the size of data by 33%?

Base64 converts every 3 bytes (24 bits) into 4 characters (each representing 6 bits). This 4/3 ratio results in approximately 33% size increase, plus potential padding characters.

What is the difference between Base64 and Base64URL?

Base64URL is a URL-safe variant that replaces '+' with '-' and '/' with '_', and often omits padding '=' characters. This makes it safe for use in URLs, filenames, and JWT tokens.

When should I use Base64 encoding?

Use Base64 when you need to transmit binary data through text-only channels, embed images in HTML/CSS, include binary data in JSON/XML, or encode email attachments.

Can Base64 encode any type of data?

Yes, Base64 can encode any binary data including images, documents, audio files, and encrypted data. It converts any byte sequence into printable ASCII characters.

Related Tools

Related Terms

Related Articles