Computers store everything as binary โ sequences of 0s and 1s. When you need to send binary data (an image, a PDF, a certificate) through a system designed to handle text โ an email, an HTTP header, a JSON API, an XML document โ you have a problem. Many text-based protocols cannot reliably handle arbitrary binary bytes. Characters like null bytes, control characters, or bytes above 127 can corrupt or terminate the transmission.
Base64 solves this by converting binary data into a safe subset of 64 printable ASCII characters that travel reliably through any text-based system.
Base64 uses a 64-character alphabet: AโZ (26), aโz (26), 0โ9 (10), plus + and / (2). The encoding process works in three steps:
If the input is not divisible by 3, padding characters (=) are added to make the output length a multiple of 4.
Encoding the text "Man":
Every 3 bytes of input becomes exactly 4 characters of Base64 output โ a 33% size increase.
src="data:image/png;base64,iVBORw0KGgo..." โ avoids an extra HTTP request for small icons.username:password are Base64-encoded in the Authorization header.-----BEGIN CERTIFICATE----- headers.This is the most common misconception. Base64 is purely an encoding scheme โ it is completely reversible by anyone without any key or secret. Seeing Base64 in an HTTP header does not mean credentials are protected. HTTP Basic Auth, for example, encodes credentials in Base64 but is effectively plaintext unless the connection uses HTTPS.
For actual confidentiality, you need encryption (AES, RSA, etc.). Base64 just makes binary data text-safe.
Standard Base64 uses + and /, which have special meanings in URLs (+ = space, / = path separator). Base64url substitutes:
+ โ -/ โ _= is often omittedThis makes Base64url safe to use in URLs, filenames, and query parameters without percent-encoding. JWTs, OAuth tokens, and many modern APIs use Base64url rather than standard Base64.
No. Base64 is encoding, not encryption. Anyone who receives Base64 data can decode it instantly without any key. It provides zero security or confidentiality โ it exists purely to represent binary data safely as printable ASCII text. Never use Base64 to protect sensitive information.
Exactly 33% larger. Every 3 bytes of input produce 4 characters of output (plus padding). A 1MB image embedded as Base64 in HTML becomes approximately 1.37MB of text. This is why inline Base64 images are only efficient for very small assets like icons.
Standard Base64 uses + and / which are special URL characters. Base64url substitutes - for + and _ for /, making it safe in URLs and filenames without percent-encoding. It also usually omits the = padding. JWTs and most modern OAuth tokens use Base64url.
Inline Base64 images make sense for very small assets (icons under ~1โ2KB) where the HTTP request round-trip overhead outweighs the 33% size increase. For anything larger, serving images from a CDN is more efficient โ browsers cache them, they compress well with HTTP/2, and they don't bloat HTML/CSS file sizes.