Skip to content
ToolPika

Base64 Encode and Decode

Encode text or a file to Base64, or paste Base64 to decode it. Accents and emoji work, and nothing leaves your browser.

Mode
Up to 5 MB. The file stays on your device.

Runs in your browser. Nothing you enter is sent to a server.

How it works

Encoding. Text is first converted to UTF-8 bytes, so every language and emoji is supported. The bytes are then read three at a time (24 bits) and split into four groups of 6 bits, and each group is written as one of 64 characters. If the input is not a multiple of three bytes, the output is padded with =.

Decoding. Spaces and line breaks are ignored, missing padding is added back, and a data:…;base64, prefix is removed, so you can paste Base64 straight from an email, a PEM file or an HTML image tag. If the decoded bytes are not valid text (for example, an image), the tool tells you and lets you download them as a file instead.

Files are encoded as raw bytes. Tick “As a data: URL” to get a string you can put directly in an <img src> or a CSS url().

Examples

Text Base64
foobar Zm9vYmFy
foob Zm9vYg==
café Y2Fmw6k=
😀 8J+YgA==
subjects?_d c3ViamVjdHM/X2Q= (URL-safe: c3ViamVjdHM_X2Q)

Base64 in code

Language Encode text Decode
JavaScript (browser) btoa(String.fromCharCode(...new TextEncoder().encode(s))) new TextDecoder().decode(Uint8Array.from(atob(b), c => c.charCodeAt(0)))
Node.js Buffer.from(s).toString('base64') Buffer.from(b, 'base64').toString()
Python base64.b64encode(s.encode()).decode() base64.b64decode(b).decode()
Shell echo -n 'text' | base64 echo 'dGV4dA==' | base64 -d

Frequently asked questions

What is Base64 used for?

It turns any data into plain text made of 64 safe characters (A–Z, a–z, 0–9, + and /), so binary data such as images or keys can travel through systems built for text, like email, JSON, XML, URLs and HTML.

Is Base64 encryption?

No. Anyone can decode Base64 instantly; it hides nothing. Never use it to protect passwords or personal data.

Why is Base64 bigger than the original?

Every 3 bytes become 4 characters, so encoded data is about 33% larger, plus up to two = signs of padding at the end.

What is URL-safe Base64?

A variant that replaces + with - and / with _, and usually drops the = padding, so the result can be used in URLs and file names without escaping. It is common in JSON Web Tokens (JWT). The decoder here accepts both variants automatically.

Why does btoa() fail on my text in JavaScript?

The browser's btoa() only accepts characters up to code 255, so text with emoji or most non-Latin letters throws an error. Encode the text as UTF-8 bytes first, which is what this tool does.