DoraPDF / Blog

Base64 Encode and Decode Explained (With Simple Examples)

By the DoraPDF team · 5 min read · Updated 2026-11-26
Base64 Encode and Decode Explained (With Simple Examples)

Sooner or later you run into a long string like SGVsbG8= in an email header, an API response or a web page's source, and wonder what it is. That is Base64. This guide explains what Base64 encoding is used for, how it turns bytes into text, how to Base64 decode a string in your browser, and the mistakes that trip people up, using short examples you can try yourself.

What Base64 actually is

Base64 is a way of writing any data, including images and other binary files, using only 64 safe characters: A–Z, a–z, 0–9, + and /, with = used as padding at the end.

Why bother? Many systems were built to carry plain text and can damage raw bytes: email, URLs, JSON fields, HTML attributes, config files. Base64 converts bytes into characters those systems will not mangle, and the receiver converts them back.

How it works, in one example

Take the word Man. In bytes it is three characters, 24 bits. Base64 cuts those 24 bits into four groups of 6 bits. Each 6-bit number (0 to 63) is looked up in the 64-character alphabet:

Input Base64
Man TWFu
Hi SGk=
Hello SGVsbG8=
café Y2Fmw6k=

Two things follow from this:

Non-English text works too, as long as it is first turned into UTF-8 bytes. That is why café gives Y2Fmw6k=: the é takes two bytes.

What Base64 is used for

Base64 is not encryption

This is the most important point in the whole post. Anyone can decode Base64 in a second; there is no key and no secret. If you see a password or API key "protected" with Base64 in a config file, treat it as plain text. To protect data you need real encryption. To protect a document, use something like Protect PDF, which sets an actual password.

How to encode or decode Base64 on DoraPDF

  1. Open the Base64 Encoder / Decoder.
  2. Choose the Mode: Encode → Base64 or Decode ← Base64.
  3. Paste your text into the input box. The result appears live in the output box.
  4. Click Copy to grab it.

To encode a file, scroll to "Or encode a file" and drop any file on the drop area. You get a complete data URL (with the file type at the front, for example data:image/png;base64,) that you can paste straight into an <img src=""> or a CSS url().

Text is handled as UTF-8 in both directions, so accented letters, Urdu, Arabic and emoji survive the round trip.

Base64 vs URL encoding

People often mix these up because both make text "safe". They solve different problems:

If you are building a link with a search term or a redirect address inside it, you want the URL Encoder / Decoder, not Base64. Standard Base64 output can itself contain +, / and =, which are special in URLs, so a Base64 string placed in a URL usually needs URL encoding too.

Base64url and JWTs

A JSON Web Token looks like three Base64 chunks joined by dots: header.payload.signature. It uses Base64url, where + becomes -, / becomes _, and the padding is usually dropped.

The first chunk of a typical token, eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9, decodes to {"alg":"HS256","typ":"JWT"}. To read a whole token, paste it into the JWT Decoder. It decodes the header and payload, shows them as formatted JSON, and if there is an exp claim it shows the expiry date and whether the token has already expired. Note that it does not verify the signature, so it tells you what a token says, not whether it is genuine.

Common problems and fixes

Privacy

The Base64 tool, URL Encoder and JWT Decoder all work in your browser. Text, files and tokens are processed on your device and are not uploaded. That matters with JWTs in particular: a live token is often enough to act as the logged-in user, so avoid pasting it into tools that send it to a server.

FAQ

Is Base64 secure? No. It is an encoding, not encryption. Anyone can reverse it without a key.

Why does Base64 end with = or ==? That is padding, added when the input length is not a multiple of 3 bytes.

Why is the Base64 version bigger than my file? Every 3 bytes become 4 characters, so output is about 33% larger.

Can I decode an image from Base64 here? The decoder is for text. You can turn an image into a data URL with the file encoder, and a browser can display that data URL directly.

Try the tools from this guide — free

Keep reading

Guide

Free Developer Tools Online: JSON Formatter, Regex Tester, Base64, URL Encoder, JWT Decoder, SQL and UUID

Eight small browser-based developer tools for everyday debugging: validate JSON, test regex, decode JWTs and Base64, format SQL, make UUIDs. Free.

Guide

Best Free PDF Website for Students? Why Students Choose DoraPDF

What students need from a free PDF website (no sign-up, no watermark, works on phone, private) and how DoraPDF covers the full assignment chain.

Guide

Is Paid PDF Software Worth It? Free vs Paid PDF Tools, Task by Task

Free vs paid PDF software: which everyday tasks free DoraPDF tools cover, when paying makes sense, and a 5-minute test before you renew.