Base64 Encoder / Decoder3 min readOct 21, 2026

Why Base64 Strings End With '=' (RFC 4648 Padding Rules Explained)

Understand why Base64 strings end with one or two equals signs (=). Explore RFC 4648 24-bit alignment rules and how to handle unpadded Base64.

Direct Summary (TL;DR)

The equals sign (=) in Base64 is a padding character mandated by RFC 4648. Because Base64 processes data in 3-byte (24-bit) chunks to produce 4 characters, inputs whose byte length is not divisible by 3 append one '=' (if 1 byte remains) or two '==' (if 2 bytes remain) to maintain 4-character block alignment.

Interactive Mickytool Utility

Solve this problem now with our free Base64 Encoder / Decoder

Try it instantly in your browser — zero tracking, 100% client-side privacy.

Open Base64 Encoder / Decoder

Specification & Architecture Reference

Why Base64 Strings End With '=' (RFC 4648 Padding Rules Explained) — Technical Summary
Input Byte CountRemainder (Bytes % 3)Base64 Output LengthPadding Appended
3 bytes (e.g., 'Man')0 bytes remainder4 characters ('TWFu')
2 bytes (e.g., 'Ma')2 bytes remainder4 characters ('TWE=')
1 byte (e.g., 'M')1 byte remainder4 characters ('TQ==')
4 bytes (e.g., 'Many')1 byte remainder8 characters ('TWFueQ==')

The 24-Bit Block Rule in RFC 4648

Base64 encodes binary sequences by grouping bits into chunks of 6. The lowest common multiple between an 8-bit byte and a 6-bit Base64 character is **24 bits**: $$\text{LCM}(8, 6) = 24\text{ bits} = 3\text{ octets (bytes)} = 4\text{ Base64 characters}$$

This means a standard Base64 stream always operates in 4-character quantum groups.

What Happens When Input Doesn't Divide by 3? When the input stream ends, the remaining bytes determine the padding characters:

  1. **Input length % 3 == 0:** All 24-bit blocks are fully populated. No padding is added (e.g., `"abc"` becomes `"YWJj"`).
  2. **Input length % 3 == 2:** The final block contains 16 bits of real data. These 16 bits are split into two 6-bit characters plus 4 remaining bits (padded with two zero bits to make a third character). The fourth slot is filled with `=` to maintain the 4-character block (e.g., `"ab"` becomes `"YWI="`).
  3. **Input length % 3 == 1:** The final block contains only 8 bits of data. This produces one full 6-bit character plus 2 bits padded with zeroes to form a second character. The remaining two slots are filled with `==` (e.g., `"a"` becomes `"YQ=="`).

Can You Strip Padding? Yes. Modern standards like **Base64url** (RFC 7515, used in JWT tokens) omit `=` padding entirely because the payload length can be deduced from the string's length modulo 4:

javascript
function addBase64Padding(str) {
  return str + '='.repeat((4 - (str.length % 4)) % 4);
}

Test and debug your Base64 strings with or without padding using Mickytool's **Base64 Encoder / Decoder**.

Interactive Mickytool Utility

Solve this problem now with our free Base64 Encoder / Decoder

Execute this workflow immediately without saving data on remote servers.

Open Base64 Encoder / Decoder

Frequently Asked Questions

Can a Base64 string ever end with three equals signs (===)?

No. The remainder of dividing any integer by 3 is only 0, 1, or 2. Therefore, a valid Base64 string can only ever end with 0, 1, or 2 '=' characters.

Why do JWT tokens not have '=' padding?

RFC 7515 specifies that JSON Web Signatures (JWS) use Base64url encoding without padding to avoid issues with URL parameter parsers.

Related Engineering Guides