Base64 Converter

Encode and decode text to/from Base64.

Free Online Base64 Encoder & Decoder

Base64 encoding represents binary data as ASCII text - common in APIs, data URIs, and email attachments. Dokall encodes plain text to Base64 and decodes Base64 back to readable text instantly.

Use it when debugging API payloads, working with data URIs, or encoding small strings for transport. Processing is local and immediate.

What is Base64 Encoding?

Base64 is a binary-to-text encoding scheme that represents binary data using 64 printable ASCII characters: A-Z, a-z, 0-9, +, and /. The = character is used for padding. It was designed to safely transmit binary data through systems that only handle text, such as email (MIME) and early HTTP.

Base64 is not encryption. It does not protect data - anyone can decode it. Its purpose is encoding, not security. Think of it as a way to represent arbitrary bytes as safe text characters.

How Base64 Encoding Works

Base64 takes every 3 bytes (24 bits) of input and splits them into four 6-bit groups. Each 6-bit group maps to one of the 64 characters in the Base64 alphabet. Since 3 bytes become 4 characters, Base64 output is always about 33% larger than the input.

When the input length is not a multiple of 3 bytes, padding is added. One byte of input becomes 4 characters with == padding. Two bytes become 4 characters with = padding. Three bytes need no padding. Some implementations omit the padding since the decoder can infer it from the output length.

When to Use Base64

Embedding small images in HTML or CSS as data URIs: <img src="data:image/png;base64,..."> avoids an extra HTTP request. This works well for small icons (under 2-3 KB) but is counterproductive for larger images because Base64 increases the file size by 33% and prevents caching.

Sending binary data in JSON: JSON does not have a binary type, so files, images, and cryptographic keys are often Base64-encoded as strings. The receiving end decodes the string back to bytes.

Email attachments use Base64 (via MIME) to encode binary files as ASCII text that can pass through email servers that only handle text.

Storing small binary values in text-based databases or configuration files. For example, encryption keys and certificate data are commonly stored as Base64 strings.

Base64 vs Base64url

Standard Base64 uses + and / as the 63rd and 64th characters, with = for padding. These characters have special meaning in URLs and filenames - + is a space in query strings, / is a path separator, and = is a key-value delimiter.

Base64url replaces + with - and / with _, and typically omits padding. It produces tokens safe for use in URLs, filenames, and HTTP headers without additional encoding. JWTs use Base64url encoding for this reason - each part of a JWT is Base64url-encoded so the token can be passed in URL query parameters and Authorization headers without escaping.

Base64 in Different Programming Languages

In JavaScript: btoa() encodes a string to Base64 and atob() decodes it. For binary data (Uint8Array), use the Buffer class in Node.js or the more modern approach with TextEncoder and base64 encoding utilities.

In Python: the base64 module provides b64encode() and b64decode() for standard Base64, and urlsafe_b64encode()/urlsafe_b64decode() for Base64url. These functions work with bytes objects, not strings.

In Go: the encoding/base64 package provides StdEncoding for standard Base64 and URLEncoding for Base64url, with both padded and unpadded (RawStdEncoding, RawURLEncoding) variants.

In the terminal: echo -n "hello" | base64 encodes, and echo "aGVsbG8=" | base64 -d (or --decode) decodes. The -n flag on echo is important - without it, a trailing newline gets encoded too.

Frequently Asked Questions

Is Base64 encryption?
No. Base64 is encoding, not encryption. Anyone can decode a Base64 string back to the original data without any key or password. It provides no confidentiality. If you need to protect data, use actual encryption (AES, ChaCha20) and then optionally Base64-encode the ciphertext for safe text transport.
Why is Base64 output about 33% larger than the input?
Base64 represents every 3 bytes (24 bits) as 4 characters (each encoding 6 bits). So the ratio is 4/3, a 33% increase. For example, a 3 KB file becomes about 4 KB in Base64. This overhead makes Base64 inefficient for large files - it is best suited for small payloads.
Can I use Base64 for images in HTML and CSS?
Yes. Use data URIs: <img src="data:image/png;base64,iVBOR..."> in HTML or url(data:image/png;base64,...) in CSS. This avoids an extra HTTP request. However, Base64 images increase the HTML/CSS file size by 33%, cannot be cached independently, and block rendering until decoded. Use this technique only for small images (icons, small logos) under 2-3 KB.
What is the difference between Base64 and Base64url?
Standard Base64 uses + and / as characters and = for padding. Base64url replaces + with -, / with _, and typically omits padding. Use Base64url when the encoded output needs to be safe in URLs, filenames, or HTTP headers. JWTs and many API tokens use Base64url for this reason.
How do I encode and decode Base64 in JavaScript?
In the browser: btoa('hello') returns 'aGVsbG8=' and atob('aGVsbG8=') returns 'hello'. Note: btoa/atob only handle ASCII. For Unicode text, first encode with TextEncoder: btoa(String.fromCodePoint(...new TextEncoder().encode('hello'))). In Node.js: Buffer.from('hello').toString('base64') and Buffer.from('aGVsbG8=', 'base64').toString().
Is Base64 encoding reversible?
Yes, Base64 is a lossless, bidirectional encoding. You can always convert Base64 back to the exact original bytes. This is different from hashing (one-way, irreversible) and lossy compression (some data is discarded).
What characters does Base64 use?
Standard Base64 uses 64 characters: A-Z (26), a-z (26), 0-9 (10), + and / (2), plus = for padding. Base64url replaces + with - and / with _ for URL safety. All characters are printable ASCII, making Base64 safe for text-based protocols.