user2520410
user2520410

Reputation: 479

Is padding the reason why base64 encoding is bigger?

Base 64 is takes 3 Byte (24 Bits) and represents these through 4*6 Bits. If the data cannot be divided by 3, extra bytes are taken as a kind of padding? Is this padding responsible that the base64 representation is larger than a binary encoding?

Or why is base64 bigger?

Upvotes: 2

Views: 275

Answers (2)

sharptooth
sharptooth

Reputation: 170499

Base64 is bigger because those 6-bit chunks are then typically stored in 8-bit bytes with some bits set to zero and so you move from 3 fully used bytes to 4 partially used bytes and so it effectively leads to more bytes being used. The same number of bits is used, but they are distributed over more bytes. Padding is only applied for the last one or two bytes of the source, but this 3-to-4 increase happens for all source bytes and this is why the encoding leads to increase of volume.

Upvotes: 2

Oliver Matthews
Oliver Matthews

Reputation: 7823

Base64 is bigger because it only uses 6 bits in the byte to store information, hence the need for 4 bytes of transmitted data for 3 bytes of actual information.

i.e. even though base64 is only storing 6 bits of data in one of its bytes, that byte still needs 8 bits of storage space.

Upvotes: 6

Related Questions