/
[ DEV STUDIO ]

Base64 & Data URI Utility: Strings, Files, and URL-Safe Encoding

Encode and decode binary files, SVG graphics, and UTF-8 strings into standard Base64, RFC 4648 URL-safe Base64, and embeddable Data URIs.

UPDATED: 2026-11-06
TIME: 5 min read
FORMAT: GFM // MDX

Binary files, graphic assets, and authorization tokens often need to be transmitted across channels designed solely for plain ASCII text. Converting raw 8-bit octets into 6-bit Base64 representations enables inlining assets directly into CSS rules, HTML tags, and API JSON payloads.

The Base64 & Data URI Converter provides instant, client-side encoding and decoding for both UTF-8 text strings and binary image files.


1. Standard Base64 vs. RFC 4648 URL-Safe Base64

Standard Base64 encoding utilizes 64 printable ASCII characters (A-Z, a-z, 0-9, +, /), using = for byte padding. However, the characters +, /, and = possess reserved semantic meanings in URL query parameters and path segments.

TERMINAL // CODE
┌─────────────────────────────────────────────────────────────┐
│ Character Set Comparison:                                   │
│  • Standard Base64:   A-Z, a-z, 0-9,   +   and   /   (pad =)│
│  • URL-Safe Base64:   A-Z, a-z, 0-9,   -   and   _   (no pad)│
└─────────────────────────────────────────────────────────────┘

Conversion Mapping:

  1. Replace + with hyphen -.
  2. Replace / with underscore _.
  3. Strip trailing padding = characters (optional based on consumer parser requirements).
TERMINAL // CODE
// URL-safe base64 conversion
export function toBase64Url(base64: string): string {
  return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
}

NOTE: URL-safe Base64 is the required encoding standard for JWT signatures, OAuth 2.0 PKCE code verifiers, and modern web authentication credentials.


2. Inlining Binary Media via Data URIs

A Data URI embeds raw file content directly into web documents using the standard URI scheme:

TERMINAL // CODE
data:[<mediatype>][;base64],<data>

Common Production Examples:

  • Inlining SVG Icons:
    TERMINAL // CODE
    background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==');
    
  • Inlining 1x1 Transparent PNG Spacer:
    TERMINAL // CODE
    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" alt="" />
    

3. Step-by-Step Tool Guide

TERMINAL // CODE
[ Step 1: Input Text or File ] ──▶ [ Step 2: Choose Encode / Decode ] ──▶ [ Step 3: Copy Format Output ]
  1. Enter UTF-8 text or drop any local file (PNG, SVG, PDF, JSON) into the ingestion dropzone.
  2. Select target mode: Standard Base64, URL-Safe Base64, or Data URI.
  3. Inspect generated file size metrics and byte inflation ratio (~33% expansion).
  4. Click Copy Result to copy the encoded string to your clipboard.