How to encode or decode Base64
- Paste text to encode, or a Base64 string to decode, into the input box.
- Tick Base64URL if the result will go in a URL, file name or JWT.
- Press Encode or Decode. Spaces and line breaks in Base64 input are removed automatically.
- Copy the result, or press Use as input to reverse the operation.
- To embed a file, choose it in the file section and copy the generated data URI.
How Base64 works
Base64, specified in RFC 4648, turns binary data into text using 64 safe characters: A-Z, a-z, 0-9, + and /. The encoder takes the input three bytes (24 bits) at a time and splits them into four 6-bit groups, each of which maps to one character. When the input length is not a multiple of three, the output is padded with one or two = characters.
Base64 works on bytes, not characters, so text must first be converted to bytes. The browser's built-in btoa function only accepts characters in the Latin-1 range and fails on input such as emoji. This tool converts text to UTF-8 bytes with TextEncoder first, and decodes back with TextDecoder, which is the behaviour most servers and programming languages expect.
Quick reference
| Input | Base64 | Base64URL |
|---|---|---|
Man | TWFu | TWFu |
Ma | TWE= | TWE |
M | TQ== | TQ |
?> | Pz4= | Pz4 |
??> | Pz8+ | Pz8- |
Common uses include HTTP Basic authentication headers, email attachments (MIME), JWTs, embedding small images in CSS, and storing binary values in JSON or environment variables.