Base64 is an encoding that turns any binary data (or byte sequence) into a text string using only 64 ASCII characters. It’s not encryption or compression: it’s for moving or storing binary where only text is allowed.
What is Base64 used for?
- Data URLs: embed an image or small file in HTML or CSS as
data:image/png;base64,...without a separate HTTP request. - Email (MIME): attachments and binary content are encoded in Base64 for text-based messages.
- APIs and JSON: when you need to send a file or binary in JSON, it’s often sent as a Base64 string.
- JWT: the header and payload of a JWT are Base64URL (no
+,/or=); they’re not encrypted—anyone can decode and read them. - URLs and signatures: hashes or tokens in URL parameters often use Base64URL to avoid problematic characters.
How it works (in short)
Input bytes are taken in groups of 3 (24 bits). Those 24 bits are split into 4 blocks of 6 bits; each block is mapped to one of 64 characters (A–Z, a–z, 0–9, +, /). If the bytes don’t fill a multiple of 3, padding with = is added. The result is a longer string than the original (about 33% larger).
Encode and decode
A Base64 encode/decode tool lets you paste text or upload a file, encode to Base64 and decode back. Use it for quick checks, inspecting JWT payloads (which are Base64URL) or generating test data URLs. In code, most languages have built-in or standard library support (btoa/atob in the browser, Buffer in Node.js, etc.). Remember: Base64 doesn’t protect the data; if you need confidentiality, use encryption (e.g. AES) in addition to or instead of Base64.