Base64 encoder

5 of 1 ratings

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

  1. Enter text (ensure the intended encoding, e.g., UTF-8) or upload a file (PNG, PDF, JSON, etc.).
  2. 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.
  3. 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.

Similar tools

Base64 decoder

Decode Base64 input to back to string.

5
0

Popular tools