What Is Base64?

Reviewed by Dynamic Foundries ·

Base64 is a binary-to-text encoding that represents arbitrary bytes with 64 printable ASCII characters. It converts each 3-byte group into 4 characters so binary data can move through text-oriented systems. Base64 is reversible encoding—not encryption, hashing, or compression.

Why Base64 exists

Base64 solves a transport problem: some protocols and data formats accept text but not arbitrary byte values. Representing bytes with a restricted ASCII alphabet lets images, attachments, certificates, and other binary values pass through those systems without being interpreted as control characters. RFC 4648 defines the standard Base64 and Base64URL encodings.

Base64 does not make the content secret. Anyone with the encoded string can decode it without a key. Encrypt sensitive data with an appropriate, reviewed encryption system; use Base64 only when a surrounding format needs text.

How Base64 encoding and decoding work

The encoding process follows a clear, deterministic algorithm:

  1. Read three bytes (24 bits) of the source binary data at a time.
  2. Split those 24 bits into four groups of 6 bits. Since 26 = 64, each group maps to one of 64 possible values.
  3. Map each 6-bit value to the corresponding character in the Base64 alphabet (see below).
  4. Repeat until all input bytes are processed.

Decoding is the reverse: each Base64 character is looked up in the alphabet to recover its 6-bit value, groups of four characters are combined into three bytes, and the original binary data is restored.

Base64 example

InputUTF-8 bytesBase64 output
Hello48 65 6c 6c 6f (hex)SGVsbG8=
e2 9c 93 (hex)4pyT

Base64 encodes bytes, not abstract characters. Text must first be converted to bytes with a character encoding such as UTF-8; the same character encoding must be used after decoding. The MDN Base64 guide explains this browser-specific distinction.

The 64-character alphabet

The standard Base64 alphabet (defined in RFC 4648) consists of these 64 characters:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 + /

Characters A–Z map to values 0–25, a–z to 26–51, 0–9 to 52–61, + to 62, and / to 63. The = padding character is not part of the 64-character alphabet.

Standard Base64 versus Base64URL

PropertyStandard Base64Base64URL
Values 62 and 63+ and /- and _
Padding= required unless another specification says otherwiseOften omitted when the byte length is known
Typical contextsMIME, data URLs, text payloadsURLs, filenames, JWT segments

RFC 4648 treats Base64URL as a separate encoding, not merely another spelling of standard Base64. Use the variant required by the protocol or data format you are working with.

What Base64 padding means

Because Base64 processes input in groups of three bytes, the final group may contain only one or two bytes. When this happens, the output is padded with = characters:

Padding ensures that every Base64-encoded string has a length divisible by four, which simplifies decoding. Some implementations (especially URL-safe variants) omit padding since the decoder can infer the original length.

Base64 size overhead and limitations

For every complete 3-byte input group, Base64 produces 4 output characters: 24 input bits become four 6-bit values. That is a one-third increase before any line wrapping or protocol overhead. Very short inputs vary because padding rounds the final output to a four-character group.

Common Use Cases

Email Attachments (MIME)

MIME can use Base64 as a content-transfer encoding for binary email body parts and attachments. The exact encoding depends on the sending software and message content.

Data URIs in HTML and CSS

Developers can embed small images, fonts, and icons directly into HTML or CSS using data: URLs with Base64-encoded content. Inlining removes a separate request but increases the encoded size and prevents normal resource caching, so measure the tradeoff.

APIs and JSON Payloads

REST APIs often use Base64 to transmit binary data (images, documents, certificates) within JSON objects, since JSON is a text-based format that cannot natively carry raw binary.

JWT Tokens

JSON Web Tokens encode their header and payload sections using Base64url (the URL-safe variant). This makes JWTs safe to pass in URLs, HTTP headers, and cookies without escaping issues.

Base64 compared with other encodings

Sources and review method

This guide was checked against the RFC 4648 standards-track specification for alphabets, padding, canonical encoding, and Base64URL, plus Mozilla Developer Network documentation for JavaScript and Unicode behavior. The examples were verified against the browser implementation used by the B64Decoder text tool.

Frequently Asked Questions

Is Base64 encoding the same as encryption?

No. Base64 is an encoding scheme, not an encryption algorithm. It does not provide any security or confidentiality. Anyone can decode a Base64 string back to the original data without any key or password. If you need to protect data, use proper encryption (such as AES) before optionally Base64-encoding the result for transport.

Why does Base64 increase the size of data?

Base64 converts every 3 bytes of input into 4 ASCII characters, resulting in roughly a 33% size increase. This overhead exists because each output character represents only 6 bits of data instead of the 8 bits a binary byte can hold. The tradeoff is necessary to ensure the encoded data contains only safe, printable characters.

What does the = sign mean at the end of Base64 strings?

The = character is padding. Base64 encodes data in groups of 3 bytes (24 bits). When the input length is not a multiple of 3, one or two = signs are appended so the output length is always a multiple of 4 characters. One = means two bytes were in the last group; two = signs mean only one byte was in the last group.

What is the difference between Base64 and Base64URL?

Standard Base64 uses + and / for values 62 and 63. Base64URL uses - and _ so the output fits URLs and filenames without escaping; padding is often omitted when the data length is known. RFC 4648 defines them as distinct encodings.

Can I use Base64 to encode images and files?

Yes. Base64 can encode any binary data, including images, PDFs, audio files, and executables. This is commonly done for embedding small images in HTML/CSS via data URIs, or for sending files through JSON APIs. However, keep in mind the 33% size increase — for large files, it is usually more efficient to transfer the binary data directly rather than Base64-encoding it.

Ready to try it out? Use our free Base64 Encoder/Decoder tool to encode or decode any text instantly in your browser.