Web Utilities

Base64 Encoder / Decoder

Encode text to Base64 or decode Base64 back to text. Runs entirely in your browser — nothing is sent to any server.

Options:
Plain text
0 bytes
Base64
0 bytes

Frequently Asked Questions

What is Base64 encoding and what is it used for?

Base64 is an encoding scheme that converts binary data into a string of ASCII characters using 64 printable characters (A-Z, a-z, 0-9, +, /). It's not encryption — it's a reversible encoding for safely transmitting binary data through text-based channels. Common uses: (1) Embedding images directly in HTML/CSS as data URIs (data:image/png;base64,...). (2) Encoding binary file attachments in email (MIME). (3) Passing binary data in JSON or XML payloads. (4) HTTP Basic Authentication headers (username:password encoded as Base64). (5) Encoding tokens and identifiers in URLs. Base64 adds approximately 33% overhead to the size of the original data (every 3 bytes becomes 4 characters).

What is URL-safe Base64 and when should I use it?

Standard Base64 uses + and / as characters, which have special meaning in URLs (+means space, / is a path separator). URL-safe Base64 (also called Base64url) replaces + with - and / with _, making the encoded string safe for use in URLs and filenames without percent-encoding. The padding character = is often omitted as well. URL-safe Base64 is used in: JWT tokens (JSON Web Tokens use Base64url for header and payload), OAuth state parameters, URL-safe ID generation, and any context where the encoded string will appear in a URL query parameter or path segment. If you're encoding data for embedding in a URL, always use URL-safe mode.

How do I decode a Base64 string in JavaScript, Python, or the command line?

JavaScript (browser): atob('SGVsbG8=') returns the decoded string. For encoding: btoa('Hello'). Node.js: Buffer.from('SGVsbG8=', 'base64').toString('utf8') to decode; Buffer.from('Hello').toString('base64') to encode. Python: import base64; base64.b64decode('SGVsbG8=').decode() to decode; base64.b64encode(b'Hello').decode() to encode. Command line (Linux/Mac): echo 'SGVsbG8=' | base64 --decode to decode; echo -n 'Hello' | base64 to encode. Note: atob/btoa in browsers only handle Latin-1 characters reliably. For Unicode text, use TextEncoder/TextDecoder or the encodeURIComponent workaround for full UTF-8 support.

Why does Base64 output end with == or =?

The trailing = or == characters are padding. Base64 encodes 3 bytes (24 bits) at a time into 4 characters. If the input length isn't a multiple of 3, padding is added: 1 remaining byte → two extra characters + '=='; 2 remaining bytes → three extra characters + '='. For example: 'Man' (3 bytes) encodes to 'TWFu' (no padding); 'Ma' (2 bytes) encodes to 'TWE=' (one pad); 'M' (1 byte) encodes to 'TQ==' (two pads). Padding makes the total length always a multiple of 4, which simplifies decoding. URL-safe Base64 (used in JWTs) often omits the padding = characters since it can be inferred from string length.

Base64 Encoding Explained

Base64 converts binary data into a string of printable ASCII characters. Every 3 bytes of input become 4 Base64 characters — adding about 33% overhead. It's not encryption; it's a reversible encoding used to safely transmit binary data through text-only channels.

Standard vs URL-safe Base64

Standard Base64 uses + and / characters which are special in URLs. URL-safe Base64 (Base64url) replaces + with - and / with _, making it safe for URL parameters and path segments without percent-encoding. JWTs use URL-safe Base64 for their header and payload segments.

Common Uses

Embedding images as data URIs in HTML/CSS (data:image/png;base64,...), encoding binary email attachments (MIME), HTTP Basic Authentication headers, passing binary data in JSON/XML payloads, and URL-safe token encoding.