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 |