13 KiB
| title | chunk | source | category | tags | date_saved | instance |
|---|---|---|---|---|---|---|
| Base64 - Glossary | MDN | 1/4 | https://developer.mozilla.org/en-US/docs/Glossary/Base64 | reference | web, html, css, javascript, documentation | 2026-05-05T05:24:47.878610+00:00 | kb-cron |
MDN HTML HTML: Markup language
HTML reference
HTML guides
Markup languages
CSS reference
CSS guides
Layout cookbook
JavaScriptJS JavaScript: Scripting language
JS reference
JS guides
Web APIs Web APIs: Programming interfaces
Web API reference
Web API guides
- Using the Web animation API
- Using the Fetch API
- Working with the History API
- Using the Web speech API
- Using web workers
Technologies
Topics
Learn Learn web development
Frontend developer course
- Getting started modules
- Core modules
- MDN Curriculum
- Check out the video course from Scrimba, our partner
Learn HTML
Learn CSS
Learn JavaScript
Tools Discover our tools
About Get to know MDN better
Base64
Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by transforming it into a radix-64 representation. The term Base64 originates from a specific MIME content transfer encoding. Base64 encoding schemes are commonly used to encode binary data for storage or transfer over media that can only deal with ASCII text (or some superset of ASCII that still falls short of accepting arbitrary binary data). This ensures that the data remains intact without modification during transport. Common applications of Base64 include:
- Email via MIME
- Storing complex data in XML
- Encoding binary data so that it can be included in a
data:URL
In this article
- Base64 characters
- URL and filename safe Base64
- Encoded size increase
- Last chunk
- JavaScript support
- See Also
Base64 characters
When the term "Base64" is used on its own to refer to a specific algorithm, it typically refers to the version of Base64 outlined in RFC 4648, section 4, which uses the following alphabet to represent the radix-64 digits, alongside = as a padding character:
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
URL and filename safe Base64
A common variant of this definition allows only characters that are safe to use in filenames and URL values. This version, defined in RFC 4648, section 5, omits the padding and replaces + and / with - and _.
You don't need this encoding if you are not putting the data in a path segment or query parameter — for example, data URLs have neither and can use the standard Base64 encoding.
Encoded size increase
Each Base64 digit represents 6 bits of data (64 = 26). So, three 8-bit bytes of the input string/binary file (3×8 bits = 24 bits) can be represented by four 6-bit Base64 digits (4×6 = 24 bits). This means that the Base64 version of a string or file is typically roughly a third larger than its source (the exact size increase depends on various factors, such as the absolute length of the string, its length modulo 3, and whether padding characters are used).
Last chunk
The base64 string can be partitioned into chunks of 4 characters, where the last chunk may have fewer than 4 characters. The last chunk may be padded with = characters so it's exactly 4 characters long. Excluding padding characters, the last chunk may be one of the following:
- 2 characters: encodes 12 bits representing 1 byte (8 bits) of data
- 3 characters: encodes 18 bits representing 2 bytes (16 bits) of data
- 4 characters: encodes 24 bits representing 3 bytes (24 bits) of data