DocsME
14 min readDocsMe Team

What Is Base64 Encoding?

Understand what Base64 encoding is, why it exists, what it changes about a file, and how it relates to converting a PDF to a Base64 string.

  • what is base64 encoding
  • base64 encoding definition
  • base64 explained
  • pdf me

Definition

Base64 is a binary-to-text encoding scheme. It represents any sequence of bytes — a PDF, an image, a font, an encryption key — using only 64 printable ASCII characters: the letters A–Z and a–z, the digits 0–9, and two extra symbols, usually + and /.

Because the output uses only common, printable characters, it can pass safely through systems that were designed to carry text rather than arbitrary binary data.

Why It Exists

Many of the protocols and formats the web relies on — early email standards, JSON, XML, and URLs — were built around text, not raw bytes. Some of those channels strip, change, or reject certain byte values outright.

Base64 sidesteps the problem by re-expressing binary content as text first. This is the same idea behind converting a PDF to Base64: the file's bytes become a string any text field can hold.

What It Is Not

Base64 is not encryption and not compression. It does not hide or protect data — anyone can decode it instantly — and the encoded output is always larger than the input, never smaller.

It is also not a file format. It does not know whether the bytes it represents are a PDF, a JPEG, or something else; that information has to travel alongside it, usually in a separate field or as part of a data URI.

How It Relates to PDFs

A PDF is just a sequence of bytes like any other file, so it encodes the same way as an image or a font. For the mechanics of the conversion, see how Base64 encoding works, and for a full walkthrough see the PDF to Base64 guide.

From Bytes to Base64 Characters

Base64 works on the original file 3 bytes — 24 bits — at a time. Each 24-bit group is split into four 6-bit chunks, and each 6-bit chunk (a number from 0 to 63) is looked up in a fixed alphabet to produce one output character. Three bytes in, four characters out.

This is why every Base64 string is built from the same 64 symbols, no matter what kind of file — a PDF, an image, a font — went in. See what Base64 encoding is for the bigger picture.

The Base64 Alphabet

The 64 possible 6-bit values map to: the uppercase letters A–Z (values 0–25), the lowercase letters a–z (values 26–51), the digits 0–9 (values 52–61), and finally + and / (values 62 and 63). A handful of variants swap the last two symbols — URL-safe Base64 uses - and _ instead, so the string can sit safely inside a URL.

Padding With =

A 24-bit group only forms cleanly when the input length is a multiple of 3 bytes. When a file's last group has only 1 or 2 bytes left over, Base64 pads the missing bits with zeros and appends one or two = characters to the output so decoders know exactly how many of the final bits were real data.

Padding does not carry any information from the file — it only marks where real content ends, so a decoder can stop at the right place.

A Small Worked Example

Encoding the two letters "Hi" produces the string "SGk=". The bytes for H and i form 16 bits, which split into three full 6-bit chunks plus 2 leftover bits padded with zeros — three real characters (S, G, k) followed by one = padding character, because the input was 2 bytes, not a multiple of 3.

Why the Output Is About 33% Larger

Three bytes of binary data always become four characters of text, a 4:3 ratio — about 33% bigger. A PDF that is 900 KB on disk becomes a Base64 string close to 1.2 MB. This is the main tradeoff to plan around; see the size guidance in the PDF to Base64 guide.

Encoding

The process of converting data from one representation to another — in this context, turning a PDF's binary bytes into a Base64 text string. See how Base64 encoding works for the mechanics.

Decoding

The reverse of encoding: converting a Base64 string back into the original binary bytes. A correctly decoded PDF is byte-for-byte identical to the file that was encoded.

Data URI

A string that combines a Base64-encoded value with a prefix describing its file type, in the form data:application/pdf;base64,.... Browsers and some viewers use the prefix to know how to render the data. See Base64 vs Data URI for when each form applies.

Binary Data

Data stored as raw bytes rather than human-readable text. A PDF, like any file format, is binary data at the byte level, regardless of how much text it visually contains.

MIME Type

A label such as application/pdf that identifies what kind of content a piece of data is. APIs and browsers use the MIME type to decide how to handle, display, or decode a file.

API Payload

The data sent in the body of an API request or response. A Base64-encoded PDF often lives inside a JSON payload as one field among several — see how to use a Base64 PDF in a JSON API request for a typical structure.