Base64 encoder
Encode text or files to Base64 online for safe transmission and storage in systems that only accept ASCII. This Base64 encoder converts raw bytes into a text-friendly formatâperfect for embed image as Base64, Base64 encode string online, convert file to Base64, and building data URLs for web apps.
What is Base64 encoding?
Base64 is a binary-to-text encoding that maps every 3 bytes into 4 printable characters using a 64-symbol alphabet (AâZ
, aâz
, 0â9
, +
, /
) plus padding =
. Itâs widely used in email (MIME), web APIs, and storage to represent arbitrary bytes as text. If youâve searched for âwhat is Base64 encodingâ or âBase64 vs hexâ, the short answer is: Base64 is more compact than hex (â33% overhead vs 100%).
How to use the Base64 Encoder
- Enter text (ensure the intended encoding, e.g., UTF-8) or upload a file (PNG, PDF, JSON, etc.).
- Choose options:
- URL-safe Base64 (
-
and_
instead of+
and/
) for tokens and URLs. - Include/strip padding (
=
) depending on your consumerâs expectations. - Line wrap at 76 chars for MIME emails, or no wrap for APIs.
- URL-safe Base64 (
- Click Encode to generate the Base64 string, then copy it or download as needed.
When should you use it?
- Embed images or fonts in HTML/CSS via Base64 data URL (convert image to Base64, Base64 image converter).
- Email attachments (MIME) that require Base64 encode file online with 76-char line breaks.
- APIs & JSON where binary must be represented as text (Base64 encoder and decoder online workflows).
- Tokenization for non-binary channels using URL-safe Base64.
Who is this for?
- Developers & DevOps embedding binaries in configs, JWT-like payloads, or testing Base64 encode/decode flows.
- Marketers & email teams preparing Base64 MIME content for campaigns.
- Designers inlining SVG/PNG as Base64 data URIs for rapid prototypes.
Best practices & caveats
- Base64 is not encryptionâit provides no secrecy. For privacy, use proper encryption.
- Overhead: Expect ~33% size increase; avoid inlining very large assets.
- Character encoding: Ensure your input text is the intended charset (commonly UTF-8). Different encodings â different outputs.
- URL-safe variant: Use
-
and_
and optionally strip=
padding for query strings and tokens (URL-safe Base64 encoder). - MIME wrapping: For emails, wrap at 76 chars per RFC 2045; for APIs, donât wrap.
Examples
Base64 encode a string
Input: "hello world"
Output: aGVsbG8gd29ybGQ=
Create a Base64 data URL for an image
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...
Command-line references
# macOS / Linux (GNU coreutils)
base64 input.bin > output.b64
base64 -d output.b64 > roundtrip.bin # decode example
# macOS (BSD base64) â wrap at 76 chars for MIME
base64 -b 76 input.bin
# Windows PowerShell
[Convert]::ToBase64String([IO.File]::ReadAllBytes("C:\path\to\file")) | Set-Content out.b64
[IO.File]::WriteAllBytes("roundtrip.bin",[Convert]::FromBase64String((Get-Content out.b64 -Raw)))
FAQ
Why do I see âinvalid paddingâ on decode?
Padding =
characters may be missing or extra. Re-pad to a length divisible by 4, or ensure the encoder didnât strip padding when the decoder expects it.
Whatâs the difference between Base64 and Base64 URL-safe?
URL-safe replaces +
//
with -
/_
, and often omits =
. Use it for URLs, cookies, and path segments.
Should I inline images as Base64 in production?
Only for small assets or critical icons. Large inlines bloat HTML/CSS and can hurt caching; prefer external files or sprites.