Base64 Encoder & Decoder Online
Convert text and files to Base64 encoding (RFC 4648) or decode Base64 back to its original form.
Docify's Base64 encoder converts text and files using the standard RFC 4648 alphabet (A-Z, a-z, 0-9, +, /) with = padding. Text encoding uses btoa(unescape(encodeURIComponent())) to properly handle UTF-8 characters. File uploads use FileReader.readAsDataURL(). Example: Hello World! encodes to SGVsbG8gV29ybGQh. For URL-safe encoding, use Base64url instead. Nothing is uploaded.
How to encode text to Base64
- Select Encode mode above.
- Paste or type your text in the left panel and click Encode, or click Upload file to encode a file directly (its Base64 appears in the output).
- Copy the result or click Download to save it.
How it works
- Text encoding uses
btoa(unescape(encodeURIComponent(input)))to convert the JavaScript string to UTF-8 bytes, then to Base64. This handles Unicode characters correctly. - Text decoding uses
decodeURIComponent(escape(atob(input)))to reverse the process. Invalid Base64 characters will throw an error. - File handling uses
FileReader.readAsDataURL()to read files as Base64. In encode mode, the Base64 payload is written to output. In decode mode, it's written to input for you to decode. - Download saves the result as a text file. This is the Base64 string or decoded text, not a binary file reconstruction.
Base64 alphabet comparison
| Standard | Index 62 | Index 63 | Padding |
|---|---|---|---|
| Base64 (RFC 4648 §4) | + | / | = |
| Base64url (RFC 4648 §5) | - | _ | Optional |
Base64 in Python and Node
The snippets below encode UTF-8 bytes with the RFC 4648 §4 alphabet (A–Z, a–z, 0–9, +, /, and = padding) and do not wrap at 76 characters. That is the same standard Base64 this page returns for text. They are not Base64url (- / _). For that alphabet, see Base64 vs Base64URL: URL-Safe Alphabet.
Node.js with Buffer
Node's Buffer encoding 'base64' is RFC 4648 standard. Pass 'utf8' so the bytes match this page's encodeURIComponent path. Use 'base64url' only when you want the URL-safe alphabet:
const encoded = Buffer.from('Hello World!', 'utf8').toString('base64');
// "SGVsbG8gV29ybGQh"
const decoded = Buffer.from(encoded, 'base64').toString('utf8');
// "Hello World!"Python with the base64 module
base64.b64encode accepts bytes only — passing a str raises TypeError. Encode UTF-8 first, then decode the result as ASCII. Avoid base64.encodebytes, which inserts a newline every 76 characters and a trailing newline this page does not add. Use urlsafe_b64encode only for Base64url:
import base64
encoded = base64.b64encode('Hello World!'.encode('utf-8')).decode('ascii')
# 'SGVsbG8gV29ybGQh'
decoded = base64.b64decode(encoded).decode('utf-8')
# 'Hello World!'Non-ASCII text follows the same UTF-8 path: café encodes to Y2Fmw6k= in Node, CPython, and this page. NFC and NFD spellings of the same letter are different byte sequences, so they encode to different Base64 strings. The stdlib CLI python -m base64 is the legacy encode() / decode() file API — the same wrap as encodebytes — not this b64encode snippet. See Base64 in the shell.
Base64 in the shell
Text encode on this page converts UTF-8 bytes with the RFC 4648 §4 alphabet and does not wrap. File encode uses the file's raw bytes the same way. GNU base64 wraps at 76 characters by default; pass -w 0 to match this page. macOS base64 already defaults to an unbroken stream. echo appends a newline, so use printf to match this page's encoding of Hello World!. CPython python -m base64 uses that same RFC 2045 wrap as GNU's default (76 characters plus a trailing newline) and has no -w 0 flag. These commands are standard Base64, not Base64url.
GNU base64 (Linux)
Coreutils base64 reads a file or stdin. Decode with -d. GNU -i means --ignore-garbage on decode — it is not an input-file flag:
# File (same bytes as this page's file encode) base64 -w 0 report.bin # Text without a trailing newline (same as this page's text encode) printf 'Hello World!' | base64 -w 0 # SGVsbG8gV29ybGQh printf 'SGVsbG8gV29ybGQh' | base64 -d # Hello World!
macOS base64
macOS ships a BSD base64 whose -i is --input. Decode with -D (or -d on recent releases). Default break count is 0:
base64 -i report.bin printf 'Hello World!' | base64 # SGVsbG8gV29ybGQh printf 'SGVsbG8gV29ybGQh' | base64 -D # Hello World!
OpenSSL base64
openssl base64 wraps at 64 characters by default. Pass -A for a single line that matches this page:
openssl base64 -A -in report.bin printf 'Hello World!' | openssl base64 -A # SGVsbG8gV29ybGQh printf 'SGVsbG8gV29ybGQh' | openssl base64 -d -A # Hello World!
CPython python -m base64
CPython can run the stdlib base64 module as a script. Default -e calls the legacy encode() file API — RFC 2045 wrap at 76 characters, with a newline after every line including the last. That matches GNU base64 with no -w, not this page and not b64encode. For Hello World! the alphabet still matches; only the trailing newline is extra. -d and -u both decode — -u is not URL-safe:
# Same alphabet as this page, plus a trailing newline printf 'Hello World!' | python -m base64 # SGVsbG8gV29ybGQh printf 'SGVsbG8gV29ybGQh' | python -m base64 -d # Hello World! # -u is decode, not urlsafe printf 'SGVsbG8gV29ybGQh' | python -m base64 -u # Hello World! # Missing padding printf 'SGVsbG8gV29ybGQ' | python -m base64 -d # binascii.Error: Incorrect padding
Windows certutil -encode writes PEM headers (BEGIN CERTIFICATE) around the payload — strip those lines before comparing with this page. python -m base64 reads a file argument or stdin (-). A second path is ignored. Empty stdin encodes or decodes to empty and exits 0 — this page also writes empty Base64 for empty text. --help is not a flag (short getopt only); -h prints usage. The last of -e / -d / -u wins. Decode uses a2b_base64 per line, so spaces and other non-alphabet bytes are discarded; extra = after a complete group is ignored; missing padding raises binascii.Error. Base64url - / _ are discarded too, then padding usually fails — use the Base64url encoder. There is no wrap-disable flag and no URL-safe flag. For the URL-safe alphabet, see Base64 vs Base64URL: URL-Safe Alphabet; do not swap + / / by hand and call it Base64url without also handling padding.
FAQ
- Does this tool upload my data?
- No. All encoding and decoding runs in your browser using JavaScript btoa() and atob() functions. Files are processed locally with FileReader — nothing is sent to a server.
- How does Base64 encoding work?
- Base64 converts binary data to ASCII text using 64 characters (A-Z, a-z, 0-9, +, /) plus = for padding. Every 3 bytes become 4 characters. This tool uses the standard RFC 4648 alphabet.
- What is the difference between Base64 and Base64url?
- Standard Base64 uses + and / which are special in URLs. Base64url (RFC 4648 §5) replaces them with - and _ and often omits padding. Use Base64url for URLs, cookies, and filenames.
- Can I encode files with non-ASCII content?
- Yes. For text, this tool uses btoa(unescape(encodeURIComponent(input))) to properly handle UTF-8 characters. For binary files, use the Upload file button which reads the file as a data URL.
- Why does my decoded output look corrupted?
- The input might be Base64url (with - and _) instead of standard Base64. Or it might be binary data being displayed as text. For Base64url, use our Base64url decoder instead.
- Does encoding preserve Unicode normalization?
- Base64 preserves exact byte sequences without normalization. NFC é (U+00E9) and NFD e+combining-accent encode to different Base64 strings because they are different UTF-8 byte sequences.