Skip to content
Tools

Base64 Encoder & Decoder

Encode plain text into Base64 or decode Base64 back into readable text instantly. Everything runs locally in your browser.

Visible pane

Plain text

0 chars

Loading editor…

Waiting for input

Everything happens locally in your browser. Your data is never uploaded.

What is Base64?

Base64 is a way of writing arbitrary binary data using only 64 printable characters: A–Z, a–z, 0–9, and two more — + and / in the standard alphabet. It exists because a great deal of software was built to carry text and behaves badly, or refuses outright, when handed raw bytes.

Email is the original example. SMTP was specified for 7-bit ASCII, so a mail server was free to mangle anything else. Base64 solves that by re-spelling the bytes of an attachment using characters every system already agrees on. The same reasoning applies wherever bytes have to survive a text-shaped channel: a JSON field, an HTTP header, a URL, a CSS file.

Plain text
Many hands make light work.
The same text, Base64 encoded
TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcmsu

Nothing has been hidden and nothing has been lost — the second line is the first one, written in a smaller alphabet. That is worth holding onto, because it is the source of the single most common misunderstanding about Base64, which the section below on encryption returns to.

How Base64 encoding works

The mechanism is arithmetic, not magic. A byte holds 8 bits and there are 256 of them; a Base64 character holds 6 bits and there are 64. The lowest common multiple of 8 and 6 is 24, so the conversion works in 24-bit blocks — three bytes in, four characters out.

Three bytes become four characters
CharactersMan
Bytes7797110
Bits010011010110000101101110
Regrouped010011010110000101101110
Values1922546
Base64TWFu

Read the table downwards. The three characters Man are the bytes 77, 97 and 110. Written as bits and joined together they make 24 bits. Those 24 bits are re-cut into four groups of six, each group is a number from 0 to 63, and each number picks a character from the alphabet. Man becomes TWFu.

Two details follow from this. First, the size: four characters for every three bytes is a 33% increase, which is why encoded output is always noticeably larger. Second, padding. Not every input divides neatly into three, so when one or two bytes are left over the final group is completed with = characters — one if two bytes remained, two if one did.

Three bytes divide evenly — no padding
"Man"   →   TWFu
Two bytes leave a gap — one =
"Ma"    →   TWE=
One byte leaves a bigger gap — two =
"M"     →   TQ==

There is one more step that trips implementations up, and it happens before any of this. Base64 encodes bytes, but text is not bytes until you choose an encoding. This tool converts text to UTF-8 first, which is why caféencodes as five bytes rather than four, and why emoji work at all. Tools built on the browser’s older btoa function skip that step and simply throw on anything outside Latin-1.

Encode vs decode

The two directions are exact inverses, and either can be run on any input — which makes it easy to reach for the wrong one.

Encoding takes bytes and produces Base64. It never fails: every possible sequence of bytes has an encoding. If the result looks wrong, the question is what went in, not what the encoder did.

Decoding takes Base64 and produces bytes, and it can fail, because not every string is valid Base64. Three things go wrong in practice:

  • A character outside the alphabet. Almost always a value that was truncated, url-encoded on the way, or copied along with the text around it.
  • Padding in the wrong place. Usually two separate values that have been concatenated — decode them one at a time.
  • An impossible length. Base64 can never have exactly one character left over after groups of four, so that means characters are missing from the end.

There is a fourth outcome that is not a failure at all: the Base64 is perfectly valid, but the bytes it produces are not text. That is what happens when you decode an image or a PDF. This tool says so explicitly and lets you download the bytes, rather than showing you a screenful of replacement characters and calling it an error.

Because the two operations are inverses, the round trip is the quickest way to check yourself: encode, press Swap, and you should be looking at what you started with.

Common use cases

The pattern is always the same: bytes need to travel through something that only carries text.

Email attachments

The original reason Base64 exists. SMTP was specified for 7-bit text, so MIME encodes attachments into the printable ASCII range and wraps them at 76 characters. Every attachment you have ever sent travelled this way.

APIs and HTTP headers

HTTP Basic authentication sends user:password as Base64 — which is encoding, not protection, and is why it is only acceptable over TLS. Binary values in headers are encoded for the same reason: headers carry text.

JSON payloads

JSON has no type for raw bytes. A file, a thumbnail or a signature travelling inside a JSON document has to become a string first, and Base64 is the conventional way to do it.

JWT tokens

A JSON Web Token is three URL-safe Base64 segments joined by dots. Decoding the middle one shows the claims — which is a useful reminder that a JWT's payload is readable by anyone holding it; the signature proves it has not been altered, not that it is private.

Images and data URIs

A data: URI embeds a file directly in HTML or CSS as Base64, removing a request. Worth it for a small critical icon, a poor trade for anything larger, since the asset grows and can no longer be cached on its own.

HTML and CSS

Inline fonts, SVGs and background images all use the same data URI mechanism. Content Security Policy hashes and integrity attributes are Base64 too — there, it is carrying a digest rather than a file.

Is Base64 encryption?

No. This is the most consequential misunderstanding about Base64, and it is worth being blunt: Base64 provides no security whatsoever.

Encryption depends on a secret. Without the key, ciphertext is unreadable — that is the whole point. Base64 has no key. The alphabet is published in an RFC, the algorithm is a page long, and every language ships a decoder. Anyone who can see the encoded value can read the original, and this page will do it for them in the time it takes to paste.

The confusion is understandable, because encoded text looks scrambled. But looking scrambled is not a security property. Three operations get mixed up here, and they do genuinely different jobs:

  • Encoding — reversible by anyone, no key. Its job is compatibility: getting data through a channel intact. Base64, URL percent-encoding and UTF-8 are all encodings.
  • Hashing — not reversible at all. Its job is integrity and identification: the SHA-256 of a file tells you whether the file changed, and cannot give you the file back.
  • Encryption — reversible only with a key. Its job is confidentiality. AES and RSA are encryption; Base64 is not.

Two everyday consequences. HTTP Basic authentication sends your credentials as Base64, which is why it is only acceptable over HTTPS — the encoding protects nothing, the transport does. And a JWT’s payload is Base64, not encrypted: anyone holding the token can read every claim in it, which is all a JWT decoder does. The signature proves the token has not been altered; it does not make it private. Never put anything in a JWT payload that the bearer should not see.

The rule is simple. Treat Base64 exactly as you would treat the original data. If it needs protecting, encrypt it — and then, if you like, Base64 the ciphertext so it survives the journey.

Advantages and limitations

What it is good at

  • Universality. The alphabet is safe in almost every text context, and every platform has an implementation. Nothing has to be negotiated.
  • Exactness. Encoding and decoding are lossless. The bytes that come out are the bytes that went in, every time.
  • Simplicity. No configuration, no state, no failure modes worth speaking of on the encoding side.
  • Predictable size. The output length is a formula, not a guess, which makes it easy to budget for.

What it is not good at

  • It is not security. Worth repeating, because it is the mistake with actual consequences.
  • It costs a third more space. Every time, in transfer, in storage and in memory. On a large payload that is a real bill.
  • It resists compression. Encoded output has less redundancy than the bytes behind it, so compressing afterwards works poorly. Compress first, then encode.
  • It defeats caching when inlined. An image embedded in a page as a data URI cannot be cached separately from that page, and is re-downloaded every time the page changes.
  • It is unreadable to people. An encoded config value gives a reviewer nothing to review. Encode at the boundary where it is needed, not throughout.

A reasonable default: use Base64 where a text-only channel forces your hand, keep the encoded form as close to that boundary as you can, and prefer a plain file reference to an inlined one whenever the asset is big enough for the difference to matter.

Frequently asked questions

Is this Base64 encoder free?

Yes. Encoding, decoding, file support, batch processing, statistics and downloads are all free, with no account, no usage cap and no paid tier. Nothing is held back.

Is my data uploaded anywhere?

No. Everything happens inside your browser. The text you paste and the files you open are processed by JavaScript running on your own machine — nothing is sent over the network, stored or logged. You can confirm this by watching your browser's network panel, or by disconnecting from the internet after the page loads: the tool keeps working.

Is Base64 secure? Is it encryption?

No, and no. Base64 is an encoding, not encryption: there is no key, no secret and nothing to break. Anyone who has the encoded text can decode it in seconds — this page will do it. Treat Base64 exactly as you would treat the original data. If something needs to be kept secret, it needs encryption, and Base64 is at most the wrapper you put around the ciphertext afterwards.

Can I decode Base64 online here?

Yes. Switch to the Decode tab and paste the value. Whitespace and line breaks are ignored, both the standard and URL-safe alphabets are accepted, and padding is optional — so a value copied out of an email header, a PEM block or a JWT will decode as it stands.

Can I encode files?

Yes. Upload a file or drop it onto the tool. Files are read as bytes rather than as text, so images, PDFs and archives encode correctly rather than being corrupted on the way in. Select several files at once and each is processed separately, with its own result to copy or download. The limit is 20 MB per file.

Why is Base64 larger than the original text?

Because it trades size for safety. Base64 represents every three bytes using four characters drawn from a 64-character alphabet, which is a ratio of 4:3 — about 33% larger, plus up to two padding characters. That is the cost of being able to carry arbitrary bytes through a channel that only reliably handles text.

Can I encode Unicode characters and emoji?

Yes. Text is converted to UTF-8 bytes first and those bytes are encoded, so accented letters, CJK characters, Cyrillic, and emoji — including multi-part ones like 👩‍💻 — all encode and decode exactly. This is worth checking in any tool you use: implementations built on the browser's older btoa function throw an error on anything outside Latin-1.

What is the difference between standard and URL-safe Base64?

They differ in two characters. Standard Base64 (RFC 4648 §4) ends its alphabet with + and /, both of which have meaning inside a URL and have to be escaped. The URL-safe variant (§5) uses - and _ instead, so the result can be dropped into a query string, a path segment or a filename untouched. JWTs use the URL-safe form, usually without padding. Decoding here accepts either without being told which.

What does the = at the end mean?

It is padding. Base64 works in groups of three bytes, and when the input does not divide evenly the final group is completed with one or two = characters so the output length is always a multiple of four. It carries no data. Some formats — JWTs in particular — drop it, which is why padding is optional here in both directions.

Why does my Base64 fail to decode?

Usually one of three things: a character outside the alphabet, which normally means the value was truncated or copied with surrounding text; padding in the wrong place, which usually means two values were concatenated; or a length that cannot be right, which means characters are missing from the end. The tool names which of the three it found and points at the exact line and column.

Can I decode Base64 back into an image or a PDF?

Yes. If the decoded bytes are not valid text — as they will not be for a PNG or a PDF — the tool says so rather than showing you nonsense, and the Download button saves the real bytes with a sensible extension guessed from the file's signature. The text shown on screen in that case is only a preview.

Does Base64 compress data?

The opposite. Base64 makes data about a third larger. If you need something smaller, compress it first and encode the compressed bytes — compressing after encoding works far less well, because Base64 output has less redundancy for a compressor to exploit than the original bytes do.

Should I Base64-encode images in CSS or HTML?

Sometimes. Inlining a small icon as a data URI removes a network round trip, which can be worth it for something tiny and above the fold. Beyond a few kilobytes the trade turns bad: the asset grows by a third, it can no longer be cached separately from the page, and it blocks rendering of whatever it is embedded in. Small and critical, yes; anything else, keep it as a file.

Is Base64 the same as encryption, hashing or URL encoding?

No, and the three are often confused. Base64 is reversible and keyless, so it hides nothing. Hashing is one-way — you cannot get the input back — and is used for integrity and passwords. Encryption is reversible but only with a key, and is what actually protects data. URL encoding solves a narrower problem: escaping the handful of characters that have meaning in a URL, rather than representing arbitrary bytes as text.

Does the tool work offline?

Once the page has loaded, yes. All encoding and decoding is local, so you can disconnect and keep working. A connection is only needed to load the page in the first place.

Popular tools

↑ ↓NavigateOpenEscClose