Websites and web tools
Base64 Encoding: Free Resources and How to Use Them
Base64 turns binary data into plain text made of 64 safe characters, so it can travel through systems that only handle text. You rarely need to pay for anything to work with it: the tools are built into operating systems, browsers and programming languages. This page explains the encoding and points to those free resources.
How Base64 works
Base64 takes the input three bytes at a time, which is 24 bits, and splits them into four groups of 6 bits. Each 6-bit value, from 0 to 63, maps to a character: A to Z, a to z, 0 to 9, plus + and /. If the input length is not a multiple of three, the output is padded with one or two = signs.
The size cost
Because every 3 bytes become 4 characters, Base64 output is about 33 percent larger than the input, before any line breaks.
Free tools you already have
- Linux and macOS terminal:
base64 file.pngencodes andbase64 -ddecodes on GNU systems; macOS also accepts-Don older versions. - Windows:
certutil -encode in.bin out.txtandcertutil -decodework in a command prompt. - Browser console:
btoa('text')encodes andatob(...)decodes. These only handle Latin-1 text, so encode Unicode to bytes first withTextEncoder. - Python: the standard
base64module offersb64encode,b64decodeandurlsafe_b64encode. - Node.js:
Buffer.from(data).toString('base64')andBuffer.from(str, 'base64').
The reference documents
RFC 4648 is the standard that defines Base64, the URL-safe variant and related encodings such as Base32 and Base16. The data URL scheme, used to embed small files directly in HTML or CSS, is defined in RFC 2397. MIME email uses Base64 with line breaks every 76 characters. Reading the relevant sections of these documents settles most disagreements about padding and alphabets.
Variants to watch
| Variant | Characters 62 and 63 | Padding |
|---|---|---|
| Standard | + and / | = required |
| URL and filename safe | - and _ | Often omitted |
| MIME | + and / | = required, lines wrapped at 76 |
JSON Web Tokens use the URL-safe alphabet without padding. If a decoder rejects a string, check whether it expects the other alphabet or needs the padding restored.
When to use it and when not to
- Good: tiny icons inlined to save a request, binary data inside JSON, email attachments, basic auth headers.
- Poor: large images on a website, because of the size cost and lost caching.
- Never: as security. Base64 is not encryption. Anyone can decode it in one command, so never use it to hide passwords or API keys.
Online converters and privacy
Web-based converters are convenient, but pasting a token, a customer file or a key into a third-party site sends it to that site. For anything sensitive, use the local command line or browser console instead.