Blog · Base64 How-To

Can I Concatenate Base64 Strings?

Yes, but only if you fix the padding first. Here is how it works, why it breaks, and the right way to join Base64 strings.

You have two Base64 strings and you want to join them together. Maybe you are decoding chunks from an API, or splitting a large file across multiple requests. You try string1 + string2 and hit Decode. It fails. What went wrong?

The short answer: you can concatenate Base64 strings, but you need to handle the padding correctly. Each independent Base64 string ends with padding characters (=) that make no sense in the middle of a combined string. Strip those, then join.

Why Concatenating Base64 Fails

Base64 encodes 3 bytes into 4 characters. If your input is not a multiple of 3 bytes, padding (= or ==) is added to round it up. Each Base64 string is a complete, self-contained encoding.

When you naively concatenate them, you get this:

String A: SGVsbG8= ("Hello")
String B: V29ybGQ= ("World")
Naive join: SGVsbG8=V29ybGQ=
The = in the middle breaks the decoder.

The Fix: Strip Padding, Then Join

Remove the trailing = characters from each string before concatenating. The combined Base64 value will be decoded as one continuous byte stream.

// JavaScript
const combined = strings
  .map(s => s.replace(/=+$/, ''))
  .join('');

// Works: "SGVsbG8=" + "V29ybGQ=" becomes
// "SGVsbG8V29ybGQ" - decodes to "HelloWorld"

Here is the same in Python:

# Python
import base64

strings = ["SGVsbG8=", "V29ybGQ="]
combined = "".join(
    s.rstrip("=") for s in strings
)
result = base64.b64decode(combined)
# b'HelloWorld'

When Does This Actually Come Up?

Concatenating Base64 strings is useful in a few real scenarios:

  • Streaming API responses. A large file is returned as Base64 chunks. You need to reassemble them before decoding.
  • MIME multi-part messages. Email attachments split across MIME boundaries use chunked Base64.
  • Database-stored fragments. Binary data stored as Base64 across multiple rows or columns.
  • Log file reassembly. Debug logs that dump Base64 in fixed-length lines.

What About Base64URL?

Base64URL (used in JWTs and URL parameters) often omits padding entirely. If you are working with Base64URL strings, you can concatenate them directly without stripping anything. Our online Base64 decoder auto-detects both formats.

One More Thing: Newlines

Some tools split Base64 output into 76-character lines (MIME standard). If your strings have line breaks, strip those too before joining:

const clean = base64String.replace(/\s/g, '');

Need to decode or encode Base64?

Try our free online tool. Live encoding, no sign-ups, works right in your browser.

Open Base64 Tool