# Base64 Size Calculator

> Computes the length of the Base64 encoding of a given number of bytes (4 characters per 3 bytes, padded with =), the 33 % overhead, the size with MIME/PEM line breaks and the length of a data: URI.

- Calculator id: `base64-size` · Category: Developer & IT (`developer`) · Tool name: `calculate_base64_size`
- Canonical page: https://tttkmbb.com/developer/base64-size · This document: https://tttkmbb.com/developer/base64-size.md · JSON definition: https://tttkmbb.com/developer/base64-size.json

## Purpose

Computes the length of the Base64 encoding of a given number of bytes (4 characters per 3 bytes, padded with =), the 33 % overhead, the size with MIME/PEM line breaks and the length of a data: URI.

**Use when:** You need to know how large a file becomes when embedded as Base64 in JSON, email (MIME) or a data URI, or how many bytes a Base64 string decodes to.

**Do not use when:** You need to actually encode or decode data, or you are sizing Base32/Base16 output (8 characters per 5 bytes, 2 per byte).

## Input

| Parameter | Type | Unit | Required | Description |
| --- | --- | --- | --- | --- |
| `size_bytes` | integer | bytes | required | Number of bytes before encoding. (min 0, max 1000000000000000) |
| `line_length` | integer | characters | optional, default 0 | Characters per line when the output is wrapped (76 for MIME per RFC 2045, 64 for PEM); 0 = single line without breaks. (min 0, max 1000) |
| `mime_type` | string |  | optional, default "image/png" | Media type written into the data: URI prefix (data:<mime>;base64,). |

## Output

| Field | Type | Unit | Description |
| --- | --- | --- | --- |
| `encoded_characters` | integer | characters | 4 × ceil(size_bytes / 3) characters including padding. |
| `padding_characters` | integer |  | Number of trailing = characters (0, 1 or 2). |
| `overhead_percent` | number | % | (encoded − raw) / raw × 100; tends to 33.33 % for large inputs. |
| `encoded_with_line_breaks` | integer | characters | Encoded length plus a CRLF (2 characters) after every line of line_length characters; equals encoded_characters when line_length = 0. |
| `line_count` | integer |  | Number of lines when wrapped (1 when not wrapped). |
| `data_uri_characters` | integer | characters | Length of data:<mime_type>;base64,<encoded> (no line breaks). |
| `data_uri_prefix` | string |  | The prefix that precedes the Base64 payload. |
| `decoded_from_encoded` | string |  | How to recover the byte count from an encoded length: 3 × encoded / 4 − padding. |

## Formula

`encoded = 4 × ceil(size_bytes / 3); padding = (3 − size_bytes mod 3) mod 3; lines = ceil(encoded / line_length); with_breaks = encoded + 2 × lines; data_uri = encoded + length('data:' + mime_type + ';base64,')`

RFC 4648 section 4 Base64 with = padding; MIME (RFC 2045) wraps at 76 characters with CRLF line endings, PEM at 64. Unpadded variants (base64url in JWTs) are shorter by padding_characters.

## Data Sources

- RFC 4648 – The Base16, Base32, and Base64 Data Encodings — https://www.rfc-editor.org/rfc/rfc4648 (standard, retrieved 2026-09-24)
- RFC 2045 – MIME Part One: Format of Internet Message Bodies (section 6.8, Base64 with 76-character lines) — https://www.rfc-editor.org/rfc/rfc2045 (standard, retrieved 2026-09-24)

Data freshness: `static`. Deterministic formula with fixed constants; results never go stale. Inputs supplied by the caller determine the output.

## API

- `GET https://tttkmbb.com/api/v1/calculate/base64-size?size_bytes=…`
- `POST https://tttkmbb.com/api/v1/calculate/base64-size` with JSON body `{"inputs": {…}}`
- Response: unified envelope (`success`, `request`, `result.values`, `result.units`, `sources`, `freshness`, `timestamp`, `next_actions`, `links`); see https://tttkmbb.com/docs/response-format.md
- Schema: https://tttkmbb.com/api/v1/calculators/base64-size · OpenAPI operationId `calculate_base64_size` in https://tttkmbb.com/openapi.json
- Authentication: none. Rate limit: fair use, see https://tttkmbb.com/docs/rate-limits.md.

## MCP

- Server: `https://tttkmbb.com/mcp` (Streamable HTTP, JSON-RPC 2.0, no auth)
- Tool:  `run_calculator` with `{"calculator_id": "base64-size", "inputs": {…}}`

## Example

- 3 bytes: inputs `{"size_bytes":3,"line_length":0}` → `{"encoded_characters":4,"padding_characters":0,"overhead_percent":33.33,"encoded_with_line_breaks":4,"data_uri_characters":26}`
- 1,000,000 bytes with MIME line breaks: inputs `{"size_bytes":1000000,"line_length":76}` → `{"encoded_characters":1333336,"padding_characters":2,"overhead_percent":33.33,"line_count":17544,"encoded_with_line_breaks":1368424,"decoded_from_encoded":"3 × 1333336 / 4 − 2 padding = 1000000 bytes"}`

```
GET https://tttkmbb.com/api/v1/calculate/base64-size?size_bytes=3&line_length=0
```

## Limitations

You need to actually encode or decode data, or you are sizing Base32/Base16 output (8 characters per 5 bytes, 2 per byte). RFC 4648 section 4 Base64 with = padding; MIME (RFC 2045) wraps at 76 characters with CRLF line endings, PEM at 64. Unpadded variants (base64url in JWTs) are shorter by padding_characters. All values are computed from the formula above; no measurement or live data is involved.

## FAQ

**Why is Base64 33 % larger?**

Every 6 bits of input become one 8-bit ASCII character, so 3 bytes turn into 4 characters (4/3 = 1.333); padding adds up to 2 more characters at the end.

**How many bytes does a Base64 string of length L decode to?**

3 × L / 4 minus the number of trailing = characters (L must be a multiple of 4 when padded).

**Does gzip undo the overhead?**

Partly: Base64 text compresses to roughly the size of the compressed original plus a few percent, but only if the transport compresses it (e.g. HTTP content-encoding).

## Related

- [Data Storage Converter](https://tttkmbb.com/conversion/data-storage.md) — Convert the resulting byte counts between KB, MiB and other units.
- [Download Time Calculator](https://tttkmbb.com/everyday/download-time.md) — Transfer time of the encoded payload.
- [Text Hash Calculator](https://tttkmbb.com/developer/text-hash.md) — Digest of the same data.
