NathanTools

Base64 Encode & Decode

Paste text to encode it as Base64, decode a Base64 string back to text or a file, or drop an image to get its data URI.

100% free No sign-up Works on any device

Report a bug

Base64 Encode / Decode

Input

Output

Converts as you type. Nothing leaves your browser. Ctrl + Enter copies the result.

Updated November 2026 · Follows RFC 4648 · Runs in your browser

How to encode or decode Base64

  1. Text: type or paste into the Input box and choose Encode, Encode (URL-safe) or Decode. Text is handled as UTF-8, so accents and emoji work.
  2. Files and images: open File to Base64 and drop the file to get its Base64 string and a data URI.
  3. Base64 to file: paste the Base64 and choose Decode. If it's a file rather than text, a preview and a Download button appear.
  4. Use Encode each line separately for lists, or Wrap at 76 characters for email (MIME) and PEM-style output.

How Base64 works

Base64 reads data 3 bytes (24 bits) at a time and splits them into four 6-bit groups. Each group is a number from 0 to 63, which picks one character from the alphabet A–Z a–z 0–9 + /. Here's Man:

StepMan
Bytes7797110
Bits010011010110000101101110

Regrouped into 6 bits: 010011 010110 000101 101110 = 19, 22, 5, 46, which are the characters TWFu. When the input isn't a multiple of 3 bytes, the output is padded with =: Ma becomes TWE= and M becomes TQ==.

Where Base64 is used

UseExample
Email attachments (MIME)Files are Base64-encoded and wrapped at 76 characters per line
Data URIs<img src="data:image/png;base64,iVBORw0…"> embeds small icons in HTML or CSS
HTTP Basic authenticationAuthorization: Basic dXNlcjpwYXNz is user:pass encoded, not encrypted
JSON Web TokensThe header and payload are URL-safe Base64
Certificates and keys (PEM)The text between -----BEGIN CERTIFICATE----- lines
APIs and JSONSending images or files inside a JSON field

Standard vs URL-safe Base64

StandardURL-safe (Base64URL)
Characters 62 and 63+ and /- and _
Padding= requiredUsually omitted
Used inEmail, data URIs, PEM filesURLs, file names, JWTs

Base64 in code and on the command line

WhereEncodeDecode
JavaScriptbtoa(str) (Latin-1 only; use TextEncoder for UTF-8)atob(b64)
Pythonbase64.b64encode(data)base64.b64decode(b64)
C# / .NETConvert.ToBase64String(bytes)Convert.FromBase64String(b64)
JavaBase64.getEncoder().encodeToString(bytes)Base64.getDecoder().decode(b64)
PHPbase64_encode($data)base64_decode($b64)
Linux / macOSbase64 file.pngbase64 -d file.txt > file.png
Windows PowerShell[Convert]::ToBase64String([IO.File]::ReadAllBytes("file.png"))[IO.File]::WriteAllBytes("file.png", [Convert]::FromBase64String($b64))

When not to use Base64

  • For security. Base64 hides nothing. Encrypt secrets and hash passwords instead.
  • For large images on web pages. Embedded images are 33% larger, can't be cached separately and block rendering. Keep data URIs for tiny icons under a few KB.
  • For compression. It always makes data bigger. Compress first (for example with gzip), then encode if you must send it as text.

Need to escape text for a URL or a web page instead? Use the URL encoder or the HTML entity encoder.

Frequently asked questions

Base64 turns any data, text or binary, into a string made of 64 safe characters: A–Z, a–z, 0–9, + and /. Every 3 bytes become 4 characters, so the data can travel through systems that only handle text, such as email, JSON, XML and URLs. It's defined in RFC 4648.

No. Base64 is an encoding, not encryption: anyone can decode it instantly without a key. Never use it to hide passwords or secrets. Use real encryption, or a password hash such as Argon2 or bcrypt for passwords.

Base64 works in groups of 3 bytes. If the data length isn't a multiple of 3, the last group is padded: one = means the final group had 2 bytes, == means it had 1. URL-safe Base64 usually drops the padding, and this decoder accepts input with or without it.

About 33%, because every 3 bytes become 4 characters. A 300 KB image becomes about 400 KB of Base64 text, plus a little more if lines are wrapped. That's why embedding large images as Base64 data URIs usually slows a page down.

Switch to the File tab and drop the image. You get the raw Base64 string and a ready-to-use data URI (data:image/png;base64,…) that you can paste into an <img> tag or CSS. Nothing is uploaded.

Paste the Base64 (with or without the data: prefix) and choose Decode. If the result is a file rather than text, the tool detects the type (PNG, JPG, GIF, WebP, PDF, ZIP and more), previews images and offers a download.

A variant (Base64URL) that replaces + with - and / with _ and usually omits the = padding, so the result can sit in URLs and file names without extra escaping. JSON Web Tokens use it.

Comments

No comments yet.

Share this tool

Base64 Encode / Decode

Favorites

Drag to reorder, or use the arrows. Categories and the tools inside them can both be moved.

Saved in this browser. Sign in to keep them on every device.

Esc
↑ ↓ to moveEnter to open