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.

Reviewed by Daniel Agrici, Founder & Lead Developer

Reviewed 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)\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.

References

Reviewed by Daniel Agrici, Founder & Lead Developer ยท Editorial policy