What Is Base64 Encoding?
Base64 is a standardized binary-to-text encoding scheme defined in RFC 4648. It takes raw binary data or 8-bit octet sequences and translates every three bytes (24 bits) into four 6-bit chunks. Each 6-bit chunk maps directly to one of 64 printable characters from the standard ASCII index: uppercase letters A–Z, lowercase letters a–z, digits 0–9, and symbols + and /. When the source byte count is not divisible by three, padding characters (=) are appended to preserve length alignment.
How to Encode Text to Base64
To encode text, each character is converted into its underlying UTF-8 byte representation. The 8-bit binary values are grouped into 24-bit blocks, sliced into 6-bit increments, and mapped to the Base64 alphabet table:
How to Decode Base64
Base64 decoding reverses the process: each Base64 character is mapped back to its 6-bit numeric value. Four 6-bit numbers are concatenated into a 24-bit binary stream and unpacked into original 8-bit bytes, which are decoded as UTF-8 text or written to a binary file:
Base64 vs Base64URL
In standard Base64, the 62nd and 63rd index characters are + and /. Because both symbols have reserved syntax in URLs and URL query strings, transmitting standard Base64 in HTTP parameters can cause severe parsing errors unless percent-encoded. The Base64URL variant solves this by introducing two safe substitutions:
- Plus sign (
+): replaced with a minus sign (-). - Slash (
/): replaced with an underscore (_). - Padding (
=): padding characters are typically omitted in JWTs and URL query strings because the payload length can be calculated programmatically.
Is Base64 Encryption?
Common Uses of Base64
API Payloads & Webhooks
Safely embedding binary data, PDF receipts, or cryptographic keys inside REST and GraphQL JSON payloads.
Inline Data URLs
Embedding SVG icons, favicons, or thumbnail images directly into HTML and CSS files using data:image/png;base64,....
Email MIME Attachments
SMTP email systems historically only supported 7-bit ASCII. Base64 encodes binary file attachments into compliant ASCII blocks.
JSON Web Tokens (JWT)
JWT headers, claims, and signatures are encoded with Base64URL to enable seamless transmission inside HTTP Authorization headers.
Binary-to-Text Transport
Storing raw byte sequences, salts, initialization vectors (IVs), and certificate hashes in text-only databases or XML files.
Source Map Assets
Webpack, Vite, and frontend bundlers embed inline JavaScript sourcemaps directly at the bottom of minified code via Base64.