Base64 Encode & Decode

Convert text, images and files to Base64, or Base64 back to text or a file. Results update as you type, and nothing leaves your device.

Text to encode

0 chars

Base64

0 chars

What is Base64 used for?

Base64 writes any data, including images, PDFs and text in any language, using just 64 safe characters (A–Z, a–z, 0–9, + and /). That lets binary data travel through places built for plain text: JSON and XML payloads, email attachments, data: URIs that embed an image straight into HTML or CSS, HTTP Basic authentication headers, JSON Web Tokens, and certificates in PEM files. It is an encoding, not encryption: anyone can decode it.

How it works

  1. Pick Encode to turn text or a file into Base64, or Decode to turn Base64 back.
  2. Type or paste, or choose, drop or paste a file. The result updates as you type.
  3. Set the options you need: text encoding, URL-safe alphabet, no padding, line breaks, or one result per line. Images can come out as a data URI, an <img> tag, CSS or Markdown.
  4. Copy or download the result. Decoded files are recognised (PNG, PDF, ZIP…), previewed, and downloaded with the right extension.

How Base64 encoding works: a worked example

Base64 reads the input three bytes (24 bits) at a time and splits them into four 6-bit numbers, each from 0 to 63. Each number picks a character from the alphabet A–Z (0–25), a–z (26–51), 0–9 (52–61), + (62) and / (63). Take the word Man:

  1. The bytes are M = 77, a = 97, n = 110: in binary 01001101 01100001 01101110.
  2. Regrouped into 6 bits: 010011 010110 000101 101110 = 19, 22, 5, 46.
  3. Looked up in the alphabet: 19 = T, 22 = W, 5 = F, 46 = u. So Man becomes TWFu.
  4. When the input doesn't divide into threes, the end is padded: Ma becomes TWE= and M becomes TQ==.

Four characters for every three bytes is why Base64 is always about a third bigger than the original. A 30 KB image becomes about 40 KB of text.

Base64 variants compared

The core algorithm is the same; the alphabet, padding and line length differ by where the result is going.

Base64 variants and where they are used
VariantCharacters 62–63PaddingUsed for
Standard (RFC 4648)A–Z a–z 0–9 + /Yes (=)JSON payloads, HTTP Basic auth, most APIs
URL-safe / Base64URLA–Z a–z 0–9 - _Usually omittedJWTs, URLs, file names, WebAuthn
MIME (RFC 2045)StandardYesEmail attachments: lines of at most 76 characters
PEM (RFC 7468)StandardYesCertificates and keys: 64-character lines between BEGIN/END lines
Data URI (RFC 2397)StandardYesdata:image/png;base64,… inside HTML, CSS and Markdown

The decoder here accepts all of them: standard or URL-safe characters, with or without padding, wrapped across lines or not, and whole data: URIs. Apart from typos, the one thing it rejects is a string that mixes both alphabets, which no encoder produces and usually means the text was altered.

Image to Base64, and Base64 to image

To embed an image in a web page, email template or Markdown file, choose it in Encode mode and set Output to Data URI, HTML <img> tag, CSS background-image or Markdown image. The <img> tag includes the image's width and height, which stops the page jumping as it loads.

Inline images suit small icons, logos and single-file HTML. For anything over a few kilobytes, a normal image file is usually better: it is a third smaller, the browser can cache it, and it doesn't hold up the rest of the page. Shrink an image before encoding it with the image compressor or image resizer.

Going the other way, paste the Base64 or data URI into Decode mode. The first bytes identify the format (a PNG always starts iVBORw0KGgo, a PDF JVBERi0, a JPEG /9j/), images and audio are previewed, and Download saves the file with the right extension. Base64 copied out of JSON often includes \n or quotes: the line breaks are ignored, but remove the quotes.

Why the same text gives different Base64

Base64 encodes bytes, not letters, so the result depends on how the text is turned into bytes first. é is w6k= in UTF-8, 6Q== in Latin-1 and 6QA= in UTF-16LE. UTF-8 is right almost everywhere on the web. Choose UTF-16LE to build a PowerShell -EncodedCommand, which requires it. If decoded text shows é where an accented letter should be, the charset doesn't match: switch Text encoding.

Invisible characters count too. hello encodes to aGVsbG8=, but echo hello | base64 gives aGVsbG8K because echo adds a line break.

Base64 on the command line

Commands to encode and decode Base64 on each system
SystemEncodeDecode
Linuxbase64 file.png > file.txtbase64 --decode file.txt > file.png
macOSbase64 -i file.png -o file.txtbase64 --decode -i file.txt -o file.png
Windows (cmd)certutil -encode file.png file.txtcertutil -decode file.txt file.png
PowerShell[Convert]::ToBase64String([IO.File]::ReadAllBytes("file.png"))[IO.File]::WriteAllBytes("file.png", [Convert]::FromBase64String($b64))
Text in a shellprintf '%s' 'hello' | base64printf '%s' 'aGVsbG8=' | base64 --decode

Windows' certutil -encode wraps its output in -----BEGIN CERTIFICATE----- lines even for files that aren't certificates. Delete those two lines before using the Base64 elsewhere.

Common mistakes

  • Treating Base64 as security. An API key or password in Base64 is still in plain sight. To prove data hasn't been changed, publish a SHA-256 from the hash generator instead.
  • Base64 in a URL. Standard Base64's +, / and = get mangled in query strings. Use URL-safe Base64, or percent-encode the value with the URL encoder.
  • Decoding a JWT as one string. A JSON Web Token is three Base64URL parts joined by dots. Paste it into the JWT decoder to read the header and claims and check the signature.
  • Encoding twice. If decoding gives you more Base64 instead of readable text, the data was encoded twice. The tool notices and offers Decode again.
  • Expecting text from a file. Base64 of an image or PDF decodes to bytes, not words. The tool detects that and offers the file for download instead of showing garbled text.

Working with JSON payloads that carry Base64 fields? Tidy them in the JSON formatter first.

Frequently asked questions

How do I convert an image to Base64?

In Encode mode, choose or drop the image (or paste a screenshot). The Base64 appears at once, and the Output menu turns it into a ready-to-paste data URI, an HTML <img> tag, a CSS background-image rule or a Markdown image. Copy it, or download it as a .txt file if it's long.

How do I convert Base64 back to an image, PDF or other file?

Switch to Decode and paste the Base64 or the whole data: URI. The tool recognises PNG, JPEG, GIF, WebP, SVG, PDF, ZIP, MP3, MP4 and other common formats from their first bytes, shows images and audio in a preview, and offers a download with the right file extension.

Is Base64 encryption? Is it secure?

No. Base64 is an encoding: anyone can reverse it instantly without a key, so it hides nothing. It exists to carry binary data through systems that only accept text. To protect data, encrypt it; to check it hasn't changed, use a hash such as SHA-256.

Why is Base64 about 33% bigger than the original?

Every 3 bytes (24 bits) become 4 characters of 6 bits each, so the output is 4/3 the size of the input, plus up to two = signs of padding. Line breaks every 76 characters, as email uses, add about another 3%.

What does the = or == at the end mean?

It's padding. Base64 works in groups of 3 bytes; when the input length isn't a multiple of 3, the last group is padded with one = (2 bytes left over) or == (1 byte left over). 'Man' encodes to TWFu, 'Ma' to TWE= and 'M' to TQ==. Some formats, such as JWTs, leave the padding out; this decoder accepts it either way.

What is URL-safe Base64 (Base64URL)?

A variant defined in RFC 4648 that uses - and _ instead of + and /, because + and / have special meanings in URLs and file names, and usually drops the = padding. JSON Web Tokens and many APIs use it. Tick URL-safe (and No padding) to produce it; the decoder recognises it automatically.

Why does my decoded text show odd characters like é instead of é?

The text was encoded in one character set and decoded in another. 'é' is what the UTF-8 bytes for 'é' look like when read as Latin-1. Change Text encoding: most modern data is UTF-8, PowerShell's -EncodedCommand and many Windows APIs use UTF-16LE, and older Western systems use Latin-1.

Why does echo hello | base64 give a different result from this page?

echo adds a line break, so the terminal encodes 'hello' plus a newline: aGVsbG8K. This page encodes exactly what's in the box: 'hello' is aGVsbG8=. Use echo -n or printf '%s' in the terminal to leave the newline out.

Can I decode a data URI?

Yes. Paste the whole thing, starting with data:image/png;base64, and the tool reads the media type from the prefix, decodes the rest and offers the file for download. Data URIs without ;base64 are percent-encoded instead; decode those with the URL decoder.

Is my data uploaded anywhere?

No. Encoding and decoding run in your browser, files included: they are read from your device into this tab and never sent to a server. Your options (mode, text encoding, line breaks) are remembered on this device; the text and files are not.

What's the largest file I can encode?

Up to 100 MB, which becomes about 133 MB of Base64. Only the first 200,000 characters are shown in the box so the page stays responsive; Copy and Download use the full result. For bigger files, the base64 command on Linux and macOS or certutil on Windows works better.

Advertisement