Skip to main content

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.

Share this calculator

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)\nConvert to bytes: 72 101 108 108 111 44 32 87 111 114 108 100 33\n\nGroup into 3-byte chunks and convert to 4 Base64 chars:\n[72,101,108] -> SGVs [108,111,44] -> bG8s [32,87,111] -> IFdv\n[114,108,100] -> cmxk [33,pad,pad] -> IQ==\n\nResult: SGVsbG8sIFdvcmxkIQ==\nOutput: 20 characters (54% overhead for short string)\nURL-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)\n\nDecode Base64 to bytes, then UTF-8:\nResult: {\"sub\":\"1234567890\",\"name\":\"John Doe\"}\n\nThis is a JSON object typically found as the payload\nof a JSON Web Token (JWT), containing the subject ID\nand 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.

References