About the Base64 Encoder/Decoder
Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format. It is one of the most commonly used encoding methods in web development, used for embedding images in CSS, sending email attachments, encoding authentication credentials, and transmitting binary data over text-based protocols.
How Base64 Encoding Works
Base64 encoding takes every three bytes (24 bits) of binary data and converts them into four ASCII characters from a set of 64 characters: A-Z, a-z, 0-9, +, and /. If the input length is not a multiple of three, padding characters (=) are added to the output. This results in encoded output that is approximately 33% larger than the original data.
Common Uses of Base64
- Data URIs: Embedding images directly in HTML or CSS using
data:image/png;base64,...syntax, eliminating extra HTTP requests. - Email Attachments: MIME encoding uses Base64 to encode binary attachments in email messages sent over SMTP.
- HTTP Authentication: Basic Authentication encodes username:password pairs in Base64 in the Authorization header.
- JSON Web Tokens (JWT): JWTs encode their header and payload sections using Base64URL encoding.
- API Payloads: Sending binary data (files, images) as part of JSON API requests.
Base64 vs Base64URL
Standard Base64 uses + and / characters, which are not safe for URLs. Base64URL replaces + with - and / with _, and omits the padding = characters. Base64URL is used in JWTs and anywhere encoded data appears in URLs or filenames.
Important Security Note
Base64 is an encoding scheme, not an encryption method. It provides no security whatsoever. Anyone can decode a Base64 string. Never use Base64 as a means of protecting sensitive data. Use proper encryption algorithms (AES, RSA) for security.