UTF-8 Byte CounterFree online other calculator — instant results, no sign-up

Count the bytes required to encode text as UTF-8.

Inputs

Result
30 bytes

Sign in to save results and favorites.

About the UTF-8 Byte Counter

The UTF-8 Byte Counter measures how many bytes are needed to encode your text as UTF-8. It counts spaces, punctuation, and line breaks as well as visible letters, and accounts for characters that require multiple bytes. The default text, "Hello world. This is a sample.", produces a result of 30 bytes.

Text
The text to encode as UTF-8, including any spaces and line breaks; this input is a character sequence with no measurement unit.

Formula and method

B = Σᵢ₌₁ⁿ b(uᵢ), where b(u) = 1 for U+0000–U+007F, 2 for U+0080–U+07FF, 3 for U+0800–U+FFFF excluding surrogates, and 4 for U+10000–U+10FFFF. For "Hello world. This is a sample.", B = 30 × 1 = 30 bytes.
  • BTotal size of the UTF-8 encoded text, in bytes.
  • nNumber of Unicode scalar values in the text.
  • iIndex identifying each Unicode scalar value, from 1 through n.
  • uᵢThe Unicode scalar value at position i.
  • b(u)Number of bytes required to encode Unicode scalar value u in UTF-8.

Read the complete input without omitting spaces or punctuation, determine the UTF-8 encoding length of each Unicode scalar value, and add those lengths. The default text, "Hello world. This is a sample.", contains 30 ASCII characters, including its spaces and periods. Each requires one UTF-8 byte, so the total is 30 bytes.

Worked example

These are the calculator's starting values and the results it actually produces for them.

Inputs

  • TextHello world. This is a sample.

Results

  • Result30 bytes

How to use the UTF-8 Byte Counter

  1. 1Enter or paste the text into the Text field.
  2. 2Check that spaces, punctuation, and line breaks match the content you intend to measure.
  3. 3Allow the calculator to process the text, or activate its calculation control if needed.
  4. 4Read the Result in bytes; the default text, "Hello world. This is a sample.", returns 30 bytes.
  5. 5If you are checking a byte limit, compare the Result with that limit and revise the text as needed.

Reading your result

The Result row reports the total bytes required to represent the supplied text in UTF-8. For the default input, Result = 30 bytes means the encoded text occupies 30 bytes before any surrounding file, message, or protocol overhead. It is a byte count, not necessarily a count of visible characters.

Limitations

The result measures UTF-8 text only, not compressed size, file-system allocation, or HTTP and other protocol overhead. A byte-order mark added during saving is not included unless it is part of the measured input. Line-ending conversion and Unicode normalization can change the byte count, so measure the exact text that will be stored or sent. Visually identical text can have different underlying Unicode sequences. Malformed input containing unpaired UTF-16 surrogates requires encoder-specific handling, commonly replacement with U+FFFD.

Common questions

Why does the default text produce exactly 30 bytes?+

"Hello world. This is a sample." contains 30 characters, counting spaces and periods. All are ASCII characters, and UTF-8 encodes each in one byte.

Why can the UTF-8 byte count exceed the visible character count?+

Non-ASCII Unicode scalar values require two, three, or four UTF-8 bytes each. A single visible symbol can also consist of several scalar values, as with combining accents and many emoji sequences.

Do spaces and line breaks contribute to the total?+

Yes. An ordinary space requires one byte. A line break represented by LF requires one byte, while a CRLF line ending requires two; the total depends on the actual characters in the input.

Can I use this result to check a text field's byte limit?+

Yes, if the destination applies its limit to the same text encoded as UTF-8. Confirm whether it normalizes text, changes line endings, or counts serialized content such as JSON escapes, because those operations can change the size being limited.

Does the calculator save my information?+

Calculations run in your browser. While signed in, inputs and results are automatically recorded in account history; saving a result creates a separate saved record.

You might also like

Results are estimates for informational purposes and are not financial, medical or legal advice.