Base64 Encoder Decoder Calculator
Free Base64 encoder decoder Calculator for web & development. Enter parameters to get optimized results with detailed breakdowns.
Formula
Every 3 input bytes become 4 Base64 characters (6 bits each)
Base64 divides input bytes into 6-bit groups and maps each group to one of 64 printable ASCII characters. Input is padded to a multiple of 3 bytes, and output is padded with = signs to a multiple of 4 characters.
Worked Examples
Example 1: Encoding a Simple String
Problem: Encode 'Hello, World!' to Base64.
Solution: Convert each character to ASCII:\nH=72, e=101, l=108, l=108, o=111, ,=44, (space)=32, W=87, o=111, r=114, l=108, d=100, !=33\n\nGroup into 3-byte blocks and convert to 4 Base64 characters:\nHel -> SGVs\nlo, -> bG8s\n Wo -> IFdv\nrld -> cmxk\n! -> IQ==\n\nResult: SGVsbG8sIFdvcmxkIQ==
Result: SGVsbG8sIFdvcmxkIQ== (18 chars from 13 input chars, 38% overhead)
Example 2: Decoding a Base64 JWT Payload
Problem: Decode the Base64 string 'eyJuYW1lIjoiSm9obiJ9' (a JWT payload).
Solution: Base64 decode character by character:\ne=30, y=50, J=9, u=46, Y=24, W=22, 1=53, l=37...\n\nGroup into 6-bit values, reconstruct bytes:\nResult bytes: 123 34 110 97 109 101 34 58 34 74 111 104 110 34 125\n\nASCII interpretation: {\"name\":\"John\"}
Result: eyJuYW1lIjoiSm9obiJ9 decodes to {\"name\":\"John\"}
Frequently Asked Questions
What is Base64 encoding and what is it used for?
Base64 is a binary-to-text encoding scheme that represents binary data using 64 printable ASCII characters (A-Z, a-z, 0-9, +, and /). It is used whenever binary data needs to be transmitted through text-based channels that do not support raw binary. Common uses include embedding images in HTML/CSS using data URIs, encoding email attachments via MIME, transmitting binary data in JSON/XML, storing cryptographic keys and certificates in PEM format, and encoding authentication credentials in HTTP Basic Auth. Base64 ensures data integrity during transmission because all 64 characters are universally supported across different systems and protocols.
How does Base64 encoding work step by step?
Base64 encoding works by converting groups of three bytes (24 bits) into four Base64 characters (6 bits each). First, the input text is converted to its binary representation using ASCII/UTF-8 values. Then the binary stream is divided into 6-bit groups. Each 6-bit group (values 0-63) is mapped to one of 64 characters: A-Z (0-25), a-z (26-51), 0-9 (52-61), + (62), and / (63). If the input length is not a multiple of three, padding characters (=) are added to make the output length a multiple of four. For example, encoding 'Hi' (two bytes) produces 'SGk=' with one padding character.
Why does Base64 increase the data size by approximately 33 percent?
Base64 increases data size because it maps every 3 bytes of input to 4 bytes of output. The ratio is exactly 4/3, or approximately 33% overhead. This happens because each output character represents only 6 bits of data but occupies 8 bits (one byte) of storage. Three input bytes provide 24 bits of data, which requires exactly four 6-bit Base64 characters. Additionally, padding with equals signs can add 1-2 extra characters. For large data like images, this 33% increase can be significant. This is why Base64 is used for encoding, not compression. When transmitting large binary files, other methods like multipart/form-data are preferred over Base64 encoding.
Is Base64 encoding the same as encryption?
No, Base64 is absolutely not encryption. Base64 is an encoding scheme that transforms data into a different representation without any security or secrecy. Anyone can decode Base64 data instantly without any key or password. It provides zero confidentiality. A common security mistake is Base64-encoding sensitive data like passwords and assuming they are protected. Base64 is as easy to reverse as converting uppercase to lowercase. For actual data protection, use proper encryption algorithms like AES-256 or RSA. Base64 encoding is often used alongside encryption, such as encoding encrypted binary output into text for transmission, but the Base64 step adds no security whatsoever.
How is Base64 used in web development with data URIs?
Data URIs allow embedding small files directly into HTML, CSS, or JavaScript using Base64 encoding. The format is data:[mediatype][;base64],data. For example, a small PNG image can be embedded as an img src attribute with the value data:image/png;base64, followed by the Base64-encoded image data. This eliminates an HTTP request, which can improve page load performance for small assets. CSS commonly uses data URIs for small icons and background images. However, Base64 data URIs increase the file size by 33% and cannot be cached independently, so they are best for files under 5-10 KB. Larger files should use traditional URL references for better performance.
What is the difference between Base64, Base32, and Base16 encoding?
These encodings differ in how many characters they use and their efficiency. Base64 uses 64 characters (6 bits per character), producing 4 output characters per 3 input bytes (33% overhead). Base32 uses 32 characters (5 bits per character), producing 8 output characters per 5 input bytes (60% overhead). It uses only uppercase letters and digits 2-7, making it case-insensitive and avoiding confusing characters. Base16 (hexadecimal) uses 16 characters (4 bits per character), producing 2 output characters per input byte (100% overhead). Base64 is most efficient for data encoding. Base32 is used in TOTP tokens and DNS names. Base16 is used for simple hex representations.