Base64 String Length: How to Calculate Output Size
Learn the formula for calculating Base64 output length: ceil(n/3)*4. Understand the 33% size increase and how padding affects total character count.
Published:
Tags: encoding, developer-tools, base64
Base64 String Length: How to Calculate Output Size Before you Base64-encode a payload and stuff it into a JSON field, database column, or HTTP header, you need to know how big the output will be. The calculation is straightforward once you understand the 3-to-4 byte ratio, and there are practical implications for storage limits, content-length headers, and URL length restrictions. The Core Formula Base64 encodes 3 input bytes as 4 output characters. For any input of bytes: Where is the ceiling function (round up to nearest integer). Equivalently: Or as code: Worked Examples Example 1: SHA-256 Hash A SHA-256 hash is always 32 bytes (256 bits). So a Base64-encoded SHA-256 hash is always 44 characters long (including the trailing ). Verify: Example 2: AES-256 Key An AES-256 key is 32 bytes.…
All articles · theproductguy.in