Base64 Encode Decode Tool
Encode text to Base64 or decode Base64 strings back to plain text instantly. Enter values for instant results with step-by-step formulas.
Reviewed for accuracy by Daniel Agrici, Founder & Lead Developer
Formula
Each 3 bytes of input become 4 Base64 characters (6 bits per character)
Base64 uses 64 printable characters (A-Z, a-z, 0-9, +, /) to represent binary data. Every 3 input bytes (24 bits) are split into 4 groups of 6 bits, each mapping to one Base64 character. Padding with = is added when the input length is not a multiple of 3 bytes.
Worked Examples
Example 1: Encoding a Simple Text String
Problem:Encode the string 'Hello, World!' to Base64.
Solution:Input: Hello, World! (13 bytes) Convert to bytes: 72 101 108 108 111 44 32 87 111 114 108 100 33 Group into 3-byte chunks and convert to 4 Base64 chars: [72,101,108] -> SGVs [108,111,44] -> bG8s [32,87,111] -> IFdv [114,108,100] -> cmxk [33,pad,pad] -> IQ== Result: SGVsbG8sIFdvcmxkIQ== Output: 20 characters (54% overhead for short string) URL-safe: SGVsbG8sIFdvcmxkIQ
Result:Encoded: SGVsbG8sIFdvcmxkIQ== | 13 bytes input -> 20 chars output
Example 2: Decoding a Base64 JWT Payload
Problem:Decode the Base64 string 'eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIn0=' to reveal the JWT payload.
Solution:Input: eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIn0= (52 chars) Decode Base64 to bytes, then UTF-8: Result: {"sub":"1234567890","name":"John Doe"} This is a JSON object typically found as the payload of a JSON Web Token (JWT), containing the subject ID and user name claims.
Result:Decoded: {"sub":"1234567890","name":"John Doe"} | Valid JSON payload
Frequently Asked Questions
What is Base64 encoding and why is it used?
Base64 is a binary-to-text encoding scheme that represents binary data using a set of 64 printable ASCII characters: A-Z, a-z, 0-9, plus (+), and forward slash (/), with equals (=) used for padding. It was designed to safely transmit binary data through systems that only support text, such as email protocols (MIME), XML documents, JSON payloads, and URL parameters. Without Base64, binary data like images, files, or encrypted content would get corrupted when transmitted through text-only channels because certain byte values would be interpreted as control characters. Base64 increases the data size by approximately 33 percent but guarantees that the encoded output consists entirely of safe, printable characters that will survive transit through any text-based system.
How does Base64 encoding work technically?
Base64 encoding works by taking every three bytes (24 bits) of input data and splitting them into four groups of six bits each. Each six-bit group maps to one of 64 characters in the Base64 alphabet. Since 2 to the 6th power equals 64, six bits can represent exactly one Base64 character. When the input length is not a multiple of three bytes, the encoder adds padding characters (equals signs) to make the output length a multiple of four characters. One byte of input becomes two Base64 characters plus two padding characters. Two bytes become three Base64 characters plus one padding character. Three bytes become exactly four Base64 characters with no padding needed. This is why Base64 encoded data is always approximately 33 percent larger than the original binary data.
What is the difference between standard Base64 and URL-safe Base64?
Standard Base64 uses plus (+) and forward slash (/) as two of its 64 characters, and equals (=) for padding. These characters have special meanings in URLs: plus represents a space, forward slash is a path separator, and equals separates parameter names from values. URL-safe Base64 (also called Base64url per RFC 4648) replaces plus with hyphen (-) and forward slash with underscore (_), and typically omits the padding equals signs entirely. This variant is essential for embedding encoded data in URLs, filenames, and other contexts where standard Base64 characters would cause parsing problems. JSON Web Tokens (JWTs) use URL-safe Base64 for their header, payload, and signature components, making it one of the most commonly encountered variants in modern web development.
Is Base64 encoding the same as encryption?
No, Base64 encoding is absolutely not encryption and provides zero security. It is a reversible encoding scheme that anyone can decode instantly without any key or secret. Base64 transforms data into a different representation format but does not hide or protect the information in any way. Thinking of Base64 as encryption is a dangerous misconception that has led to real security vulnerabilities in production software. If you need to protect sensitive data, use proper encryption algorithms like AES-256 for symmetric encryption or RSA for asymmetric encryption, combined with secure key management practices. Base64 is often used as the final step after encryption to convert the encrypted binary ciphertext into a text-safe format for transmission, but the security comes entirely from the encryption layer, not from the Base64 encoding.
Why does Base64 increase the data size by 33 percent?
The 33 percent size increase is an inherent mathematical consequence of how Base64 maps binary data to printable characters. Original binary data uses all 256 possible byte values (8 bits per byte), but Base64 only uses 64 characters (6 bits of information per character). This means every 3 bytes of input (24 bits) become 4 Base64 characters (24 bits of information encoded in 32 bits of text). The ratio is 4/3, which is approximately 1.333, representing a 33.3 percent increase. Additionally, line breaks are sometimes inserted every 76 characters per the MIME standard (RFC 2045), which adds further overhead. Padding characters at the end can add up to 2 extra characters. For large files, this overhead is significant, which is why Base64 encoding is typically used for small payloads rather than large file transfers.
Where is Base64 commonly used in web development?
Base64 is ubiquitous in modern web development across many contexts. Data URIs embed small images directly in HTML or CSS using the format data:image/png;base64 followed by the encoded image data, eliminating extra HTTP requests. Email attachments are encoded in Base64 per the MIME standard. JSON Web Tokens use Base64url encoding for their three components (header, payload, signature). API authentication often uses Base64 for HTTP Basic Auth where the username and password are combined and encoded. Client-side JavaScript uses btoa() and atob() functions for encoding and decoding respectively. SVG images can be inlined as Base64 data URIs. Source maps in minified JavaScript files use Base64-encoded mappings. Font files can be embedded in CSS using Base64 data URIs for single-request page loads.
How do I handle Unicode and special characters with Base64?
Unicode handling is a common source of bugs with Base64 encoding because the standard btoa() function in JavaScript only supports Latin-1 characters (byte values 0-255) and throws errors on multi-byte Unicode characters like emoji or non-Latin scripts. The correct approach involves first encoding the text string to UTF-8 bytes using TextEncoder, then encoding those bytes to Base64. For decoding, you reverse the process: decode Base64 to bytes, then decode those bytes as UTF-8 using TextDecoder. This two-step process ensures that characters like Chinese ideographs, Arabic script, emoji, and mathematical symbols survive the round-trip encoding and decoding without corruption. This tool handles Unicode correctly using this approach, but be aware that many online tools and code snippets do not handle Unicode properly.
What is the maximum size of data I can Base64 encode?
There is no theoretical maximum size for Base64 encoding itself, but practical limits exist in different contexts. Browser JavaScript engines typically handle strings up to several hundred megabytes before running into memory constraints. Email systems generally limit Base64 attachments to 25 to 50 megabytes depending on the provider. Data URIs in HTML have no specification limit but browsers may struggle with very large ones, and Chrome historically had issues with data URIs over 2 megabytes in certain contexts. For this web-based tool, practical limits depend on your browser memory, and inputs up to a few megabytes should work without issues. For encoding very large files, use command-line tools like the base64 command on Linux or macOS, or Python scripts, which handle streaming encoding without loading the entire file into memory.
How can I identify if a string is Base64 encoded?
Identifying Base64 encoded strings involves checking several characteristics, though no method is completely reliable since any text that happens to match the pattern would pass validation. Valid Base64 strings contain only characters from the set A-Z, a-z, 0-9, plus (+), and forward slash (/), with up to two trailing equals signs for padding. The string length should be a multiple of 4 (after removing whitespace). URL-safe Base64 uses hyphens and underscores instead of plus and forward slash and may omit padding. Additionally, the character distribution tends to be relatively uniform across the 64 characters for meaningful data, unlike natural language which has distinctive letter frequency patterns. If you suspect a string is Base64, the simplest test is to try decoding it and check if the result is meaningful text or valid data.
What are the alternatives to Base64 for encoding binary data as text?
Several alternatives to Base64 exist, each with different trade-offs in size efficiency and character set. Hexadecimal (Base16) encoding represents each byte as two hex characters (0-9, A-F), producing output twice the size of the input but is very readable and commonly used for colors, hashes, and memory addresses. Base32 uses 32 characters and is more human-friendly than Base64 because it avoids easily confused characters like 0/O and 1/l, making it popular for secret keys in two-factor authentication. Ascii85 (also called Base85) uses 85 printable ASCII characters and achieves only 25 percent overhead compared to Base64 overhead of 33 percent. It is used in PostScript, PDF files, and the Git binary diff format. Base58 is used by Bitcoin and removes ambiguous characters from Base64, optimizing for human readability while maintaining compact representation.
References
Background & Theory
History
Reviewed for accuracy by Daniel Agrici, Founder & Lead Developer ยท Editorial policy
Related Calculators
๐งฎBase64 Encoder Decoder
Calculate base64 encoder decoder with inputs, formulas, and instant results.
๐งฎURL Encode Decode Tool
Encode special characters for URLs or decode percent-encoded URL strings.
๐งฎHtml Entity Encoder
Calculate html entity encoder with inputs, formulas, and instant results.
๐งฎBase64encode Decode Calculator
Calculate base64encode decode with inputs, formulas, and instant results.
๐งฎJwt Decoder
jwt decoder. Get instant, accurate results.
๐งฎBandwidth Time Transfer Calculator
Calculate bandwidth time transfer with inputs, formulas, and instant results.
๐งฎDownload Time Calculator
Calculate download time with inputs, formulas, and instant results.
๐งฎThroughput Efficiency Calculator
Calculate throughput efficiency with inputs, formulas, and instant results.