Base64 Encoding: Complete Guide
Base64 encoding is a fundamental technique in computing that converts binary data into ASCII text. While the concept might seem simple, understanding when and how to use Base64 correctly is crucial for web developers, security professionals, and anyone working with data transmission.
What is Base64?
Base64 is a binary-to-text encoding scheme that represents binary data using a set of 64 printable ASCII characters. The name comes from the 64 characters used: A-Z (26), a-z (26), 0-9 (10), and + and / (with = for padding). The primary purpose of Base64 is to encode binary data for safe transmission through text-based systems. Email, URLs, and JSON were designed for text and can corrupt binary data. Base64 converts binary to safe text. Base64 takes every 3 bytes (24 bits) of input and converts them into 4 Base64 characters (6 bits each). This means approximately 33% size increase. Padding with = handles non-multiple-of-3 inputs. Base64 is not compression—it increases size. It's not encryption—anyone can decode it instantly. It's purely a format transformation for character safety.
Common Use Cases
Data URIs embed images directly in HTML/CSS: <img src="data:image/png;base64,...">. This reduces HTTP requests for small images but increases size. JSON APIs use Base64 for binary data like uploaded images or files. Email attachments use Base64 (MIME) for binary files. HTTP Basic Authentication encodes credentials in Base64. JWT tokens use Base64URL encoding for header, payload, and signature. Browser localStorage stores Base64-encoded binary data since it only supports strings. Base64 is appropriate for embedding, transmission, and serialization—not for security.
Base64 Overhead
Base64 converts every 3 bytes to 4 characters: 33.33% size increase. A 1 MB file becomes 1.33 MB. Consider this overhead when choosing to use Base64. Acceptable overhead: small icons under 10-20 KB, SVGs, critical assets, email attachments, API payloads where simplicity matters. Problematic overhead: large images, high-frequency APIs, mobile with limited bandwidth, large-scale storage. Compression can offset some overhead. Caching considerations matter—inline Base64 can't be cached separately.
도구 사용해보기
Base64 인코더/디코더
더 알아보기
자주 묻는 질문
Base64 인코더/디코더
자주 묻는 질문 →