By Usama Farooq · Published 3 Oct 2026 · Updated 16 Nov 2026

Base64 Explained: How Encoding Works

TL;DR — the short answer

To encode text to Base64, paste it into an encoder — “Hello” becomes SGVsbG8=. To decode, paste the Base64 string into a decoder and switch to decode mode. Base64 is encoding, not encryption: anyone can reverse it, so never use it to hide secrets. The fastest way is ToolsOfWeb’s free Base64 converter, which runs 100% in your browser — nothing is uploaded.

Base64 shows up everywhere in development: API tokens, JWT payloads, data URIs for embedded images, email attachments, and encoded blobs in logs. It exists for one reason — to represent binary data as plain ASCII text so it survives systems that only handle text (URLs, JSON, email, headers). This guide covers encoding, decoding, URL-safe mode, and file conversion, plus the mistakes that trip people up.

Try the tool

Open ToolsOfWeb’s Base64 Encode & Decode to convert text instantly, with URL-safe mode and file-to-Base64 built in.

How to encode text to Base64 (step-by-step)

  1. Open the Base64 converter and make sure “Encode → Base64” is selected.
  2. Type or paste your text into the input box — the result appears live.
  3. If the output goes into a URL or token, tick “URL-safe output”.
  4. Copy the result or download it as a .txt file.

Example: Hello, world! encodes to SGVsbG8sIHdvcmxkIQ==. Note the = padding at the end — that is normal and part of the format.

How to decode Base64 (step-by-step)

  1. Switch the converter to “Decode Base64 →”.
  2. Paste the Base64 string into the input box.
  3. The original text appears instantly. Data URIs (starting with data:…;base64,) are handled automatically.

Decoding fails? The usual causes: a typo or a missing character, text that was never Base64 (hex strings look similar), or line breaks pasted from an email client. URL-safe strings with - and _ and no padding are also accepted.

URL-safe Base64, explained

Standard Base64 output can contain + and /, which have special meaning in URLs and would need percent-encoding. URL-safe mode replaces + with - and / with _, and strips the = padding. That is the variant JWTs use for their header and payload segments. If you are building tokens or stuffing values into query strings, always use URL-safe mode.

Convert a file or image to Base64

Use the “File → Base64” tab and drop in any file up to 25 MB. You get a full data URI such as data:image/png;base64,iVBORw0KGgo…, ready to paste into an <img> tag, a CSS url(), or a JSON field. Keep in mind that Base64 inflates data by about 33%, so it suits small assets (icons, tiny images) — not multi-megabyte photos.

Base64 vs encryption: the critical difference

This is the single most misunderstood thing about Base64: it provides zero secrecy. It is a transport encoding, like writing a message in Morse code — different representation, same information. If you need secrecy, encrypt first (for example with a proper library), then Base64-encode the ciphertext for transport if you must. Encoding a password in Base64 and storing it is barely better than plaintext.

UTF-8 and emoji: why some tools break

JavaScript’s raw btoa() only handles Latin-1 characters, so naive tools mangle emoji and non-English text (Urdu, Arabic, Chinese). A correct encoder converts the string to UTF-8 bytes first, then encodes those bytes. ToolsOfWeb’s converter does this, so 😀 and multilingual text round-trip correctly.

How Base64 actually works (the 3→4 trick)

Understanding the mechanics helps you debug real problems. Base64 works on raw bytes, not characters. It takes every 3 bytes (24 bits) of input and splits them into four 6-bit groups. Each 6-bit group (values 0–63) maps to one character from a 64-character alphabet: A–Z, a–z, 0–9, then + and /. That is why the output is always about 33% longer than the input — four characters carry what three bytes used to.

When the input length is not a multiple of 3, padding fills the gap. One leftover byte produces two output characters plus ==; two leftover bytes produce three characters plus =. The padding is not decoration — it tells the decoder exactly how many bytes the final group represents. This is why “SGVsbG8=” (Hello, 5 bytes: 3+2) ends with a single =, while “SGVsbG8sIHdvcmxkIQ==” ends with two.

Practical consequence: if you ever see a Base64 string whose length is not a multiple of 4 (after stripping whitespace), something is truncated or corrupted. And if decoding gives you mojibake instead of text, the bytes were probably never UTF-8 text — check whether the source was a binary file or a different encoding.

Where Base64 hides in everyday protocols

Once you recognize the shape of Base64 — long alphanumeric strings ending in = — you start seeing it everywhere:

  • JWT tokens: the header and payload segments are Base64URL-encoded JSON. Paste any JWT into a decoder and you can read its claims (which is exactly why tokens must be signed — the content is not secret).
  • Email attachments (MIME): email is a text-only protocol from the 1980s, so every attachment you have ever received was Base64-encoded in transit. That 10 MB attachment was ~13.3 MB on the wire.
  • Data URIs: data:image/png;base64,… embeds images directly in HTML, CSS, or JSON — convenient for small assets, wasteful for large ones.
  • HTTP Basic Auth: the Authorization: Basic … header is just username:password Base64-encoded. Anyone intercepting it reads the password instantly — hence the absolute requirement for HTTPS.
  • SSH keys and certificates: PEM files wrap Base64-encoded binary key material between header lines.

Base64 vs alternatives: when to use what

EncodingSize overheadBest for
Base64+33%General binary-to-text: data URIs, JWTs, MIME, JSON blobs
Base64URL+33%Tokens and URLs — same as Base64 but safe in query strings
Hex+100%Hashes, checksums, debugging — human-readable byte-by-byte
Base32+60%Case-insensitive contexts (TOTP secrets, some DNS records)
Percent-encodingVariesEscaping special characters in URLs — not for bulk binary data

Rule of thumb: Base64 is the default for embedding binary data in text formats. Reach for hex when humans need to read or compare the output (hashes), and Base64URL whenever the output touches a URL.

Helpful follow-up tools

Worked example: reading a JWT payload without trusting it

A JWT token has three segments separated by dots: a header, a payload, and a signature. Only the middle segment is the payload, and it is Base64URL-encoded JSON, not encrypted. To inspect a token you received while debugging, copy just that middle segment and decode it on its own. Decoding the whole token at once will fail, because the dots and the signature segment are not part of the payload.

As a concrete example, the segment eyJzdWIiOiIxMjMiLCJuYW1lIjoiQW5hIiwicm9sZSI6InJlYWRlciJ9 decodes to a small JSON object with three fields: a subject value of 123, a name of Ana, and a role of reader. That tells you what the token claims, and it is useful for debugging a login flow: if the app shows the wrong name or role, you can now see whether the token itself carries the wrong claim or whether the app misread a correct token.

What decoding does not do is verify anything. Anyone can craft a token whose payload claims any role, so a server must check the signature and the expiry field before acting on a claim. Reading a payload is a debugging step only. Never paste a live production token into a tool you do not trust, and never treat a decoded role as proof of permission.

FAQs

Paste your text into a Base64 encoder and it converts it instantly — for example, “Hello” becomes “SGVsbG8=”. ToolsOfWeb’s free converter does this in your browser with full UTF-8 support, so emoji and non-English text work too.

Paste the Base64 string into a decoder and switch to decode mode. The tool converts it back to readable text. If decoding fails, check for typos, missing padding (=), or text that was never Base64.

No. Base64 is encoding, not encryption — anyone can decode it in seconds. It only makes binary data safe to transport as text. Never rely on it to hide passwords, tokens, or secrets.

Standard Base64 uses + and /, which break URLs. URL-safe Base64 replaces them with - and _ and drops the = padding, so the output works directly in query strings, filenames, and JWT tokens.

Use a file-to-Base64 tool: drop in the image and you get a data URI like data:image/png;base64,iVBORw0KGgo… which you can paste straight into HTML, CSS, or JSON. ToolsOfWeb’s converter does this entirely in your browser.

Encode or decode Base64 now

Use Base64 Encode & Decode — free, private, and instant. Text, URL-safe mode, and file-to-Base64 in one place.