Skip to content

↑↓ navigate ↵ open Esc close Search runs locally

Base64 Encode & Decode Online

Convert text and files to Base64, or decode Base64 back to readable text, images and files. Live as you type, UTF-8 safe, and nothing leaves your browser.

  • Runs in your browser
  • Nothing is uploaded
  • Free, no sign-up
0 BUTF-8
Base64
Runs in your browser. Nothing is uploaded. Tip: drop a file onto the left box

How to use the Base64 tool#

  1. Choose Encode to turn text or a file into Base64, or Decode to turn Base64 back into the original data.
  2. Type or paste into the left box, or drop a file onto it. The result appears on the right as you type.
  3. Pick options if you need them: the URL-safe alphabet (- and _), MIME line breaks every 76 characters, or a data URL for files.
  4. Copy the result or download it. Decoded images show a preview, and binary files download with the right extension.

Examples#

Encode a short text

Input
Hello, dev247!
Output
SGVsbG8sIGRldjI0NyE=

The input is 14 bytes. 14 is not a multiple of 3, so the last group is padded with one =.

Encode text with accents and emoji (UTF-8)

Input
café ☕
Output
Y2Fmw6kg4piV

é takes 2 bytes and ☕ takes 3 bytes in UTF-8, so these 6 characters become 9 bytes and exactly 12 Base64 characters, with no padding.

Decode Base64 back to text

Input
ZGV2MjQ3Lm5ldA==
Output
dev247.net

Two = signs mean the last group held only one byte of real data.

Encode credentials for HTTP Basic auth

Input
admin:s3cret
Output
YWRtaW46czNjcmV0

Send it as Authorization: Basic YWRtaW46czNjcmV0. Anyone who sees this header can decode the password, so only use Basic auth over HTTPS.

What is Base64?#

Base64 is a way to write any binary data, such as an image, a file or text in any language, using only 64 safe characters: A–Z, a–z, 0–9, + and /. Every 3 bytes of input become 4 characters of output, so the encoded text is about 33% larger than the original. In return, it can travel safely through systems that only handle plain text, such as email, JSON, HTML, XML and HTTP headers.

Base64 is defined in RFC 4648. It is an encoding, not encryption: anyone can decode it, and no key is involved.

How Base64 encoding works#

Base64 reads the input 3 bytes (24 bits) at a time and splits those 24 bits into four groups of 6 bits. Each 6-bit group is a number from 0 to 63, and that number picks one character from the Base64 alphabet. Here is the word Man, step by step:

StepMan
ASCII value7797110
8-bit binary010011010110000101101110

The 24 bits 010011010110000101101110 are regrouped into four 6-bit numbers:

6-bit group010011010110000101101110
Decimal1922546
Base64 characterTWFu

So Man becomes TWFu. Decoding simply runs the same steps backwards.

The Base64 alphabet#

Each character stands for one 6-bit value. The standard alphabet from RFC 4648 is:

ValueCharValueCharValueCharValueChar
0A16Q32g48w
1B17R33h49x
2C18S34i50y
3D19T35j51z
4E20U36k520
5F21V37l531
6G22W38m542
7H23X39n553
8I24Y40o564
9J25Z41p575
10K26a42q586
11L27b43r597
12M28c44s608
13N29d45t619
14O30e46u62+
15P31f47v63/

The = sign is not part of the alphabet. It is only used for padding.

Padding: what the = signs mean#

Base64 works in groups of 3 bytes. When the input length is not a multiple of 3, the last group is short, and = signs fill the output up to a multiple of 4 characters:

  • 1 byte left over → 2 characters + ==. Example: M → TQ==
  • 2 bytes left over → 3 characters + =. Example: Ma → TWE=
  • No bytes left over → no padding. Example: Man → TWFu

Some formats drop the padding because the length already tells the decoder how many bytes are missing. JWTs do this with Base64URL. This tool accepts input with or without padding.

How much bigger does Base64 make data?#

The encoded length is 4 × ceil(n / 3) characters for n bytes, which is about 33% more. A 300 KB image becomes about 400 KB of Base64 text. MIME email adds a line break every 76 characters, which costs roughly another 2–3%. That overhead is why Base64 is great for small files and short values, but a poor choice for embedding large images in HTML or CSS.

Where Base64 is used#

  • Data URLs: small images and fonts inlined in HTML or CSS, such as data:image/png;base64,iVBORw0KGgo…
  • Email attachments: MIME encodes binary attachments as Base64 with 76-character lines.
  • HTTP Basic authentication: user:password is Base64-encoded in the Authorization header.
  • JSON and XML APIs: binary fields like file uploads, signatures and thumbnails.
  • Certificates and keys: PEM files (-----BEGIN CERTIFICATE-----) are Base64 between the header lines.
  • Kubernetes Secrets: values under data: are Base64-encoded.
  • JWTs: the header and payload use the URL-safe variant, Base64URL.

Base64 variants#

VariantCharacters 62 and 63PaddingTypical use
Standard (RFC 4648 §4)+ /YesMost APIs, data URLs, PEM
URL-safe (RFC 4648 §5)- _Usually noJWTs, URLs, file names
MIME (RFC 2045)+ /YesEmail, lines of 76 characters

The decoder on this page accepts both + / and - _, ignores spaces and line breaks, and strips a leading data:…;base64, prefix automatically.

Base64 is not encryption. It hides nothing. Never use it to "protect" passwords, API keys or personal data. If you need secrecy, encrypt the data first (for example with AES-GCM), then Base64-encode the ciphertext if it has to travel as text.

Base64 in code#

JavaScript (browser)#

btoa() and atob() only handle Latin-1 characters, so convert text to UTF-8 bytes first:

javascript
// Text → Base64 (UTF-8 safe)const bytes = new TextEncoder().encode('café ☕');const b64 = btoa(String.fromCharCode(...bytes)); // "Y2Fmw6kg4piV" // Base64 → textconst back = new TextDecoder().decode(  Uint8Array.from(atob(b64), (c) => c.charCodeAt(0)));

Node.js#

javascript
const b64 = Buffer.from('café ☕', 'utf8').toString('base64');const text = Buffer.from(b64, 'base64').toString('utf8'); // URL-safe variant without paddingconst url = Buffer.from('café ☕').toString('base64url');

PHP#

php
$b64 = base64_encode('café ☕');          // "Y2Fmw6kg4piV" // Pass true for strict mode: returns false on invalid characters$text = base64_decode($b64, true);

Python#

python
import base64 b64 = base64.b64encode('café ☕'.encode('utf-8')).decode('ascii')text = base64.b64decode(b64).decode('utf-8') # URL-safe varianturl = base64.urlsafe_b64encode(b'\xfb\xff').decode()  # "-_8="

Command line (Linux and macOS)#

bash
echo -n 'hello' | base64            # aGVsbG8=echo 'aGVsbG8=' | base64 --decode   # hello # GNU base64 wraps lines at 76 characters; -w 0 turns that offbase64 -w 0 image.png > image.b64

Common errors and fixes#

  • InvalidCharacterError: The string to be decoded is not correctly encoded (atob in the browser)

    The input contains characters outside the standard alphabet. The usual causes are URL-safe characters (- and _), a data: prefix, or stray quotes. Paste it into this tool: it accepts both alphabets, strips data URL prefixes and points to the exact position of any invalid character.

  • binascii.Error: Incorrect padding (Python)

    The = padding was removed, which is common with JWTs and URLs. Add it back before decoding: s += "=" * (-len(s) % 4), or use base64.urlsafe_b64decode for URL-safe input.

  • btoa: The string to be encoded contains characters outside of the Latin1 range

    btoa() only accepts characters with codes up to 255. Encode the text as UTF-8 bytes first with TextEncoder, as shown in the JavaScript example above.

  • The decoded text looks garbled, like café instead of café

    The bytes are correct, but they were read with the wrong character set (Latin-1 instead of UTF-8). Decode the bytes as UTF-8. This tool always uses UTF-8.

  • The output is random symbols, or the tool says "Binary data"

    The Base64 holds a file, not text: an image, a PDF, a ZIP or compressed data. Use Download to save it. Images also show a preview. If it should be text, it may have been compressed or encrypted before it was encoded.

Frequently asked questions#

Is Base64 a form of encryption?

No. Base64 is a reversible encoding with no key, so anyone can decode it in a second. Use it to move binary data through text-only channels, never to hide secrets.

Why does Base64 end with = or ==?

The = signs are padding. Base64 encodes 3 bytes at a time, and when the input length is not a multiple of 3, one or two = fill the last 4-character group. One = means the last group had 2 bytes; == means it had 1 byte.

How much larger is Base64 than the original?

About 33% larger: every 3 bytes become 4 characters. 3 MB of data becomes roughly 4 MB of Base64, plus about 2–3% more if MIME line breaks are added.

What is the difference between Base64 and Base64URL?

Base64URL replaces + with - and / with _ so the result is safe in URLs and file names, and it usually drops the = padding. JWTs use Base64URL. This decoder accepts both.

Can I convert an image to Base64 here?

Yes. Choose Encode, drop the image onto the left box and turn on "Data URL for files" to get a string you can use directly in <img src="…"> or CSS. Decoding a Base64 image shows a preview and lets you download it.

Is my data uploaded to a server?

No. Encoding and decoding run entirely in your browser with JavaScript. Your text and files never leave your device, which you can confirm in the Network tab of your browser's developer tools.

Your next tool is one search away.

Free, private developer tools that run in your browser. No signup, nothing uploaded, no waiting.

Browse all tools

Tip: press Ctrl D to bookmark dev247.