
Base64 Encoding Explained: When to Use It and When to Avoid It
Base64 Encoding Explained: When to Use It and When to Avoid It What Base64 Actually Does Base64 converts binary data into ASCII text. It's an encoding, not encryption. // Encoding: binary → text const encoded = btoa ( ' hello ' ); // "aGVsbG8=" const decoded = atob ( ' aGVsbG8= ' ); // "hello" // In Node.js Buffer . from ( ' hello ' ). toString ( ' base64 ' ); // "aGVsbG8=" Buffer . from ( ' aGVsbG8= ' , ' base64 ' ). toString ( ' utf8 ' ); // "hello" Why Base64 Exists Email was designed for 7-bit ASCII text. When email needed to send images, attachments, or non-text data, Base64 provided a way to convert binary into printable characters. Today, the same principle applies to: Embedding images directly in CSS/HTML ( data:image/png;base64,... ) Transmitting binary over JSON APIs Storing binary in environments that only support text Real-World Example: Data URI Images <!-- ❌ External image (extra HTTP request) --> <img src= "https://example.com/icon.png" > <!-- ✅ Inline data URI (no extra
Continue reading on Dev.to Webdev
Opens in a new tab



