Developer Tools

Base64 Encoder

Encode and decode Base64 strings, binary payloads, and Data URIs with full UTF-8 and Base64URL support. 100% private in-browser.

Free to use No registration Mobile friendly Unlimited usage

What is the Base64 Encoder?

If you have ever inspected a network request in your browser's developer tools and spotted an authentication header like Authorization: Basic dXNlcjpwYXNzd29yZA==, or viewed an SVG image embedded directly inside an HTML tag as data:image/svg+xml;base64,..., you have encountered Base64 encoding. Base64 is one of the most ubiquitous data transformation formats in modern internet architecture.

The TU Web Tools Base64 Encoder & Decoder gives developers, security researchers, and system administrators an instant, secure environment to convert between plain text, raw binary data, and Base64 strings. Because all conversions occur entirely inside your browser's JavaScript engine, sensitive API credentials, private encryption keys, and confidential tokens are never transmitted across the network or logged on external servers.

How Base64 Operates: The 6-Bit Radix Mathematics

Computers fundamentally process information in 8-bit bytes (giving 256 possible byte values from 0x00 to 0xFF). However, legacy network transmission protocols—such as SMTP (email) and early HTTP—were designed strictly to transmit 7-bit printable ASCII characters. If you attempted to send raw binary files (such as an image or an encrypted key) through these channels, control characters (like Null bytes or Line Feeds) would be stripped or interpreted as transmission breaks, hopelessly corrupting the data.

Base64 (standardized in RFC 4648) solves this problem by translating 8-bit binary data into a safe set of 64 printable characters:

  • Uppercase English letters: A-Z (indices 0 to 25)
  • Lowercase English letters: a-z (indices 26 to 51)
  • Digits: 0-9 (indices 52 to 61)
  • Two special symbols: + (index 62) and / (index 63)

Because each Base64 character represents exactly 6 bits ($2^6 = 64$), the algorithm groups three 8-bit bytes ($3 \times 8 = 24\text{ bits}$) into four 6-bit numbers ($4 \times 6 = 24\text{ bits}$). This mathematical reality introduces the famous 33% size expansion: any file or string encoded in Base64 becomes approximately 33% larger than its original binary form. When the input data byte count is not divisible by three, padding characters (= or ==) are appended to complete the 4-character boundary.

Base64 vs. Base64URL: The URL-Safe Dilemma

Feature Standard Base64 (RFC 4648 §4) Base64URL (RFC 4648 §5)
62nd & 63rd Characters Plus (+) and Slash (/) Hyphen (-) and Underscore (_)
Padding Characters (=) Mandatory padding with = Omitted or stripped
URL Query Safety Unsafe (+ converts to space; / breaks URL routing) 100% URL safe without percent-encoding
Primary Applications MIME email attachments, Data URIs, Basic Auth JSON Web Tokens (JWT), OAuth 2.0 PKCE code verifiers

The Fatal URL Query Pitfall: Why Plus Signs Break

One of the most elusive bugs in web development occurs when developers place standard Base64 strings into URL query parameters without percent-encoding them. In URL query string specifications, the plus sign (+) is historically defined as shorthand for an empty space character (%20).

When your backend server (e.g. PHP's $_GET, ExpressJS, or Django) parses a query string like ?token=a+b/c=, it automatically converts the + into a space character: "a b/c=". When this string is subsequently passed to your Base64 decoding function, the decoder throws a fatal invalid character exception because space is not a valid radix-64 symbol. This is why Base64URL was created: by swapping + for - and / for _, the token travels safely through any URL router without needing percent-encoding.

Data URI Performance: When to Inline and When to Avoid

While inlining small graphics (like a 16x16 favicon or a UI arrow icon) as Base64 Data URIs saves an HTTP request, using them indiscriminately harms overall page speed. A Base64 string embedded in an HTML or CSS file cannot be cached independently of the document. If your CSS stylesheet changes by a single character, the browser must re-download the entire stylesheet, including all embedded image strings. Beyond caching penalties, mobile browsers decode Base64 in JavaScript memory before rasterizing it, creating noticeable CPU spikes on budget smartphones. For larger images, always serve modern WebP or AVIF formats via a CDN with independent HTTP caching headers.

Command-Line and Scripting Recipes

For automated pipelines, here is how to work with Base64 across standard environments:

  • Linux / macOS Bash: To encode a file, run base64 -w 0 input.png > output.b64. To decode back to a file, run base64 -d output.b64 > restored.png.
  • Python 3: Use the native base64 module:
    import base64
    encoded = base64.b64encode(b"sensitive_api_key").decode('utf-8')
    decoded = base64.b64decode(encoded).decode('utf-8')
  • PHP 8: Use base64_encode($string) and base64_decode($string, true). Always pass true as the second argument to strictly reject malformed input strings containing non-base64 characters.

Command-Line Base64 Pipelines and OpenSSL Recipes

In Unix terminal environments, shell scripts and deployment pipelines frequently leverage command-line Base64 utilities to encode binary assets, secrets, and authorization headers:

  • Standard Base64 Encoding in Linux: base64 -w 0 input.bin > output.b64 encodes raw binary data without inserting line wrap breaks, which is essential for embedding payloads into environment variables or API headers.
  • Generating Basic Auth Headers: To create an HTTP Basic Authentication string for curl requests: echo -n "username:password" | base64.
  • OpenSSL Base64 Encoding: Alternatively, using OpenSSL: openssl enc -base64 -A -in secret.key -out secret.b64. The -A flag suppresses trailing newlines.

Real-World Engineering Incident: The S3 URL Plus Sign Space Replacement Incident

Early in my cloud infrastructure work, I debugged an incident where customers were intermittently blocked from downloading signed assets from an Amazon S3 bucket. The backend application generated pre-signed URLs containing Base64-encoded cryptographic signatures that occasionally included the standard plus character (+). An unconfigured intermediate Nginx reverse proxy parsed incoming query strings according to standard application/x-www-form-urlencoded rules, silently converting every + in the query string into a literal ASCII 32 space character before proxying the request to S3. AWS S3 evaluated the altered signature against the expected cryptographic hash and returned an immediate 403 SignatureDoesNotMatch error. Resolving this required enforcing RFC 4648 Base64URL encoding (substituting - for + and _ for /) across all query parameters. Always verify whether your downstream web proxies treat plus signs as literal characters or spaces.

Benefits of using the Base64 Encoder

Correct UTF-8 handling

Accented characters, CJK scripts and emoji encode and decode without corruption, which many simpler tools get wrong.

URL-safe variant detected automatically

Paste a JWT segment or an OAuth parameter and it decodes without you having to identify which variant it is.

Both directions in one place

Encode and decode from the same screen, with size figures showing the 33% overhead Base64 adds.

Credentials stay local

Tokens and config strings are decoded in your browser, not posted to a server that might log them.

How to use the Base64 Encoder

Step 1

Select your desired conversion mode under Direction (Encode text to Base64 or Decode Base64 to text).

Step 2

Paste your text or Base64 string into the Input pane, or click Load sample.

Step 3

Optional: toggle URL safe alphabet (-_) for web token compliance, or Break output every 76 characters for MIME email formatting.

Step 4

Click Convert. The translated output renders immediately in the Output pane.

Step 5

Click Copy to copy the encoded or decoded output directly to your clipboard.

Popular use cases

  • Inspecting JWT payloads
  • Data URIs for small images
  • HTTP basic auth headers
  • OAuth state parameters
  • Config values from hosted services
  • Email attachment encoding
  • Passing binary through text-only fields
  • Decoding webhook signatures

Frequently asked questions

Base64 bridges binary data and text protocols by taking three 8-bit bytes (24 bits total) and dividing them into four 6-bit chunks (sextets). Each 6-bit value (0 to 63) maps directly to a 64-character ASCII alphabet (A-Z, a-z, 0-9, +, /). If the input byte length is not divisible by 3, padding characters (=) are appended at the end.

To embed an image directly into HTML or CSS without an extra HTTP request, prepend the MIME type and base64 declaration to the encoded output: data:image/png;base64,iVBORw0KGgo.... In CSS, use it inside a background property: background-image: url("data:image/svg+xml;base64,...");.

Ready to start using TU Web Tools?

Free, browser based utilities for developers, SEO professionals, students and businesses.

Free to use  •  Mobile friendly  •  No installation required