Base64: What It Is, What It's For and How to Encode or Decode

Guide to Base64: encoding binary as text, use in URLs, JSON and email. When to use it and size limitations.

February 4, 20262 min readBase64 Encode/Decode
Development

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.

Frequently asked questions

What is Base64?
A way to represent binary data (or any byte sequence) using only 64 ASCII characters (letters, digits, + and /). That lets you send or store binary in contexts that only accept text, such as JSON or URLs.
Does Base64 encrypt or compress?
No. Base64 is encoding, not encryption: anyone can decode it. It also doesn’t compress; encoding increases size by about 33% compared to the original. Don’t use Base64 to hide sensitive data.
What is Base64 used for?
Embedding images or files in HTML/CSS (data URLs), email attachments (MIME), storing binary in JSON or XML, and in JWTs (payload and header are Base64URL). Also for signatures or hashes in URLs.
What is Base64URL?
A variant that uses - and _ instead of + and / and omits padding with =. The result is safe to use in URLs and query parameters without further encoding. JWTs and many APIs use it.

Did you like this article?

Share it with your network

Ready to use our tools?

Try our free tools with no sign-up. JSON formatter, JWT Decoder, password generator and more.

View all tools