TEXT MEASUREMENT · TEXT & ENCODING
String Byte-Length Calculator
Measure the byte length of a string in UTF-8, UTF-16, UTF-32, Latin-1 or ASCII, with hex bytes, bit count and Base64 size. Free, instant and entirely client-side.
UTF-8 is the most compact encoding for ASCII-heavy text; UTF-16 is often smaller for CJK; UTF-32 is always four bytes per code point.
Measure the byte length of a string in UTF-8, UTF-16, UTF-32, Latin-1 or ASCII, with hex bytes, bit count and Base64 size.
- JavaScript string unit
- UTF-16
- UTF-8 bytes per character
- 1–4
- Base64 overhead
- ≈ 33%
- Client-side
- 100%
- Source: No upload
Quick answer
Measure the byte length of a string in UTF-8, UTF-16, UTF-32, Latin-1 or ASCII, with hex bytes, bit count and Base64 size. The calculator applies bytes = encode(text, encoding).length; bits = bytes × 8 and shows every intermediate value.
On this page
- 1Quick Answer
- 2Interactive Calculator
- 3String Byte-Length Calculator: Character & Byte Breakdown
- 4Key Takeaways
- 5Developer Statistics
- 6Implementation Plans
- 7Reference Tables
- 8Formulas & How to Use
- 9Worked Examples
- 10Advanced Education: String Byte-Length Calculator
- 11Language Playbooks
- 12Glossary
- 13Mistakes & Pro Tips
- 14Use Cases
- 15Related Calculators
- 16Long-Tail Answers
- 17FAQs (19)
- 18References
Interactive Calculator
Enter a value — every result updates instantly, in your browser. Free forever, no sign-up.
String Byte-Length Calculator
All inputs are calculated locally with exact integer arithmetic where possible.
Live result
12 bytes · UTF-8
8 code points · 96 bits · 16 Base64 chars
Byte length
12
Bit length
96
Code points
8
Bytes per character
1.50
String Byte-Length Calculator: Character & Byte Breakdown
Code points, code units, bytes and the exact mapping behind the result.
| Byte length | 12 |
|---|---|
| Bit length | 96 |
| Code points | 8 |
| Bytes per character | 1.50 |
| Base64 length | 16 chars |
| Percent-encoded length | 26 chars |
| Hex bytes | 48 65 6C 6C 6F 20 E4 B8 96 E7 95 8C |
| Bytes replaced | 0 |
Hex bytes
| # | Byte (hex) | Decimal |
|---|---|---|
| 0 | 0x48 | 72 |
| 1 | 0x65 | 101 |
| 2 | 0x6C | 108 |
| 3 | 0x6C | 108 |
| 4 | 0x6F | 111 |
| 5 | 0x20 | 32 |
| 6 | 0xE4 | 228 |
| 7 | 0xB8 | 184 |
| 8 | 0x96 | 150 |
| 9 | 0xE7 | 231 |
| 10 | 0x95 | 149 |
| 11 | 0x8C | 140 |
Step-by-step calculation
- 1Encode the text as UTF-8.
- 2Count the resulting bytes and multiply by eight for the bit count.
- 3Base64 length is 4 × ceil(bytes / 3).
- 4The encoding is lossless for all Unicode code points.
Key Takeaways
The 30-second version — the exact answers Google loves to feature.
- 1UTF-8 is the most compact encoding for ASCII-heavy text; UTF-16 is often smaller for CJK; UTF-32 is always four bytes per code point.
- 2Base64 expands binary data by about 33%, so a byte limit in a JSON field is smaller than the raw payload limit.
- 3Percent-encoding can expand a single UTF-8 byte to three characters (%XX).
- 4JavaScript and Java report string length in UTF-16 code units, not Unicode code points.
- 5Grapheme clusters are what users perceive as characters; code points are what Unicode encodes.
Developer Statistics & Reference Facts
Numbers worth remembering. Use them to sanity-check inputs, ranges and boundary values before shipping code.
- JavaScript string unit
- UTF-16
- UTF-8 bytes per character
- 1–4
- Base64 overhead
- ≈ 33%
- Client-side
- 100%
- Source: No upload
- Integer math
- Exact
- Source: BigInt
- User-perceived characters
- graphemes
Implementation Plans Compared: Which Workflow Fits?
Three practical ways to use this calculator. Match the plan to the risk level of your project, then follow its safeguards.
Quick check
Best for: Everyday conversions, debugging and code reviews
- Method: Paste the text or bytes into the text measurement tool and read the headline result.
- Precision: UTF-8 byte counts and Unicode code points are exact; display-width estimates are approximate.
- Safeguards: Cross-check one ASCII value, one accented value and one emoji before trusting a length rule.
Production implementation
Best for: Shipping code that reads, stores or transmits text
- Method: Use an explicit encoding, decode with errors="strict", and keep the byte and character layers separate.
- Precision: Match the exact encoding and normalization form used by the storage layer or wire protocol.
- Safeguards: Add tests for ASCII, CJK, emoji, combining marks, embedded NULs and lone surrogates.
Security review
Best for: Input validation, identifiers and URL handling
- Method: Normalize before comparing, reject unexpected control characters, and encode at the correct output context.
- Precision: Apply NFC for identifiers and the output-context encoder (HTML, URL, JSON) for the destination.
- Safeguards: Test homoglyphs, zero-width characters, double encoding and mixed-script input.
Quick Reference Tables
Widths, ranges, boundary values and language types — the lookup tables you will come back to.
Bytes for the same string
| String | UTF-8 | UTF-16LE | UTF-32LE | Latin-1 |
|---|---|---|---|---|
| Hello | 5 | 10 | 20 | 5 |
| héllo | 6 | 10 | 20 | 5 |
| 世界 | 6 | 4 | 8 | 2 (?) |
| 😀 | 4 | 4 | 4 | 4 (?) |
Lengths for the same string
| Metric | “Hello” | “héllo” | “😀” |
|---|---|---|---|
| UTF-16 code units | 5 | 5 | 2 |
| Unicode code points | 5 | 5 | 1 |
| Grapheme clusters | 5 | 5 | 1 |
| UTF-8 bytes | 5 | 6 | 4 |
| UTF-32 bytes | 20 | 20 | 4 |
Formulas & How to Use This Calculator
Core relationship
bytes = encode(text, encoding).length; bits = bytes × 8
Verification
1. Decode the output with the stated encoding. 2. Round-trip it back to the original and compare. 3. Check the code-point, UTF-16 and UTF-8 counts independently. 4. Repeat with ASCII, accented text, CJK and one emoji.
How to use — step by step
- Paste or type the text, bytes or code points into the input panel.
- Choose the encoding, notation or transformation mode that matches your data.
- Read the headline result — a converted string, a count or a similarity score.
- Open the per-character or per-byte breakdown to verify the mapping.
- Test one ASCII character, one accented character and one emoji before relying on the rule.
- Copy the result and keep the encoding and normalization form documented in your code.
Worked Examples
Real numbers and raw bits, fully worked — copy the pattern for your own code or protocol.
ASCII in UTF-8
Inputs
Hello — UTF-8
Math
5 characters × 1 byte
Result
5 bytes
CJK in UTF-8
Inputs
世界 — UTF-8
Math
2 × 3 bytes
Result
6 bytes
CJK in UTF-16LE
Inputs
世界 — UTF-16LE
Math
2 × 2 bytes
Result
4 bytes
Advanced Education: String Byte-Length Calculator
Beyond the calculator — the mental models, language rules and edge cases professionals use.
Characters, code points and code units are three different things
A user sees a character, Unicode assigns a code point, and an encoding stores one or more code units. “A” is one code point and one UTF-8 byte. “é” is one code point but two UTF-8 bytes. “😀” is one code point, four UTF-8 bytes and two UTF-16 code units. The String Byte-Length Calculator reports each layer separately because mixing them is the most common source of off-by-one bugs in length checks, database columns and truncation logic. Decide which layer your requirement actually refers to before you compare a number.
Why UTF-8 length differs from string length
UTF-8 uses one byte for U+0000–U+007F, two for U+0080–U+07FF, three for U+0800–U+FFFF and four for U+10000–U+10FFFF. A string of 100 English letters is 100 bytes, while 100 CJK characters may be 300 bytes and 100 emoji may be 400 bytes. The String Byte-Length Calculator encodes the actual text rather than estimating from the character count, so the result is exact. Use byte length for network payloads, database limits and storage budgets, and use code points or graphemes for user-facing character limits.
UTF-16 and surrogate pairs
UTF-16 stores the Basic Multilingual Plane in one 16-bit code unit. Code points above U+FFFF are split into a high surrogate in the range D800–DBFF and a low surrogate in DC00–DFFF. JavaScript, Java and Windows APIs expose UTF-16 lengths, which is why an emoji can count as two characters. The String Byte-Length Calculator shows the individual code units and flags surrogate pairs. When slicing user text, never cut between a high and a low surrogate; use a code-point-aware or grapheme-aware API instead.
Encoding conversion is not encryption
Base64, percent-encoding, HTML entities and Unicode escapes are reversible representations, not protection. Anyone can decode them without a key. Use them to move data safely through a text-only channel, not to hide secrets. The String Byte-Length Calculator makes the transformation transparent and copy-ready. If the data is sensitive, encrypt it first with an authenticated cipher, then encode the ciphertext for transport. Encoding changes the alphabet; encryption changes who can read the message.
Escaping rules are language-specific
JSON uses \uXXXX for control characters and allows a limited set of short escapes. JavaScript accepts \xXX, \uXXXX and \u{...}. Python distinguishes \x, \u and \U. C uses octal and hexadecimal escapes with different termination rules. The String Byte-Length Calculator applies one explicit convention at a time so the output matches the target language. When generating code or configuration, prefer a standard library serializer over hand-built string concatenation; it handles quotes, backslashes and control characters consistently.
Security: normalization and homoglyphs
Two different code-point sequences can render identically. “é” can be a single precomposed code point or “e” plus a combining acute accent. Unicode normalization (NFC or NFD) makes comparisons consistent. Homoglyphs from different scripts can impersonate Latin letters in usernames and URLs. The String Byte-Length Calculator reveals the underlying code points so you can spot invisible characters, zero-width joiners and mixed scripts. Normalize before comparing identifiers, and restrict allowed scripts where impersonation is a risk.
Length limits in databases and APIs
Database columns usually limit bytes or characters, and the definition varies by engine. MySQL VARCHAR(n) counts characters in the column charset; PostgreSQL varchar(n) counts characters; a byte-oriented API may count UTF-8 bytes. A 200-character emoji string can exceed a 255-byte limit. Check the actual unit, measure with the same encoding the storage layer uses, and leave headroom for normalization and future schema changes. The String Byte-Length Calculator gives you both counts from the same input.
Testing text transformations with edge cases
A text tool that works for “Hello” may fail for emoji, combining marks, right-to-left scripts or lone surrogates. Build a small corpus: ASCII, accented Latin, CJK, an emoji, a flag, a family emoji with zero-width joiners, a newline, a tab, quotes and a backslash. Run the transformation in both directions and compare the round trip. The String Byte-Length Calculator is useful for generating expected output, but the final assertion should run in the target runtime and version.
Language & Platform Playbooks
The same bit pattern behaves differently in every language. Here is how to adapt the conversion safely.
Python
Python 3 strings are sequences of Unicode code points. Use len(text) for code points, len(text.encode('utf-8')) for UTF-8 bytes, and the unicodedata module for normalization. For string byte-length calculator, prefer str.encode/decode with an explicit codec and errors='strict' so invalid input fails loudly. The standard library handles surrogate pairs and most legacy codecs; do not hand-roll UTF-8 parsing.
JavaScript / TypeScript
JavaScript strings are UTF-16 code units. Use Array.from(text) for code points, TextEncoder/TextDecoder for UTF-8, and Intl.Segmenter for grapheme clusters where available. For string byte-length calculator, avoid split('') on text that may contain emoji; it splits surrogate pairs. Buffer and btoa are not available in browsers, so use TextEncoder plus a small Base64 helper.
Java / Kotlin
Java String.length() counts UTF-16 code units; codePointCount() counts code points. Use StandardCharsets.UTF_8 with getBytes and new String for byte conversion, and Normalizer for NFC/NFD. Kotlin’s String is the same UTF-16 representation. For string byte-length calculator, specify the charset explicitly instead of relying on the platform default.
Go
Go strings are immutable byte sequences, usually UTF-8. Ranging over a string yields runes (code points); len(s) yields bytes. Use utf8.RuneCountInString for code points, []rune(s) for rune slices, and golang.org/x/text/unicode/norm for normalization. For string byte-length calculator, validate with utf8.ValidString when the input may be malformed.
Rust
Rust strings are guaranteed UTF-8. Use .chars() for code points, .bytes() for bytes, and the unicode-segmentation crate for grapheme clusters. Slicing a String by byte index can panic if it lands inside a code point. For string byte-length calculator, work with char_indices() when you need both position and character, and use encoding_rs for legacy encodings.
C / C++
C and C++ distinguish char, wchar_t, char16_t and char32_t. UTF-8 is usually stored in char arrays; convert with codecvt, ICU or a dedicated library rather than manual byte surgery. For string byte-length calculator, keep the byte length separate from the display width and validate the input before conversion. Do not assume wchar_t is 32-bit on every platform.
Glossary: Key Terms Explained
- Grapheme cluster
- The user-perceived character, which may combine a base letter with combining marks or an emoji sequence.
- UTF-16 length
- The number returned by JavaScript’s String.length, counting code units rather than characters.
- Byte length
- The number of bytes after encoding the text in a specific character set such as UTF-8.
- Base64 overhead
- Base64 encodes every three bytes as four characters, adding about 33% before line breaks.
- Bit
- A binary digit: 0 or 1. Bits are grouped into bytes, words and registers.
- Byte
- Eight bits. A byte is the smallest addressable unit on most CPUs and the usual unit for file sizes.
- Word
- The natural register width of a CPU. On modern 64-bit systems a word is usually 64 bits, though C’s int is often 32 bits.
- MSB / LSB
- Most significant bit and least significant bit. The MSB carries the largest positional weight and is the sign bit in signed integers.
Common Mistakes & Pro Tips
Mistakes that break conversions
- Calling String.length a character count when it counts UTF-16 code units.
- Comparing byte, code-point and grapheme counts without stating which one the limit uses.
- Counting UTF-16 code units and calling them characters; JavaScript and Java lengths are not character counts.
- Decoding bytes with the wrong encoding, which produces mojibake instead of an error.
- Treating Base64, percent-encoding or HTML escaping as encryption; all three are reversible by anyone.
- Truncating between surrogate halves or inside a multi-byte UTF-8 sequence.
Pro tips for production code
- Use grapheme clusters for UI limits and UTF-8 bytes for storage limits.
- Normalize text before comparing identifiers or lengths.
- Specify the encoding at every boundary: file, network, database and display.
- Normalize identifiers with NFC before comparing them, and reject control or zero-width characters where they serve no purpose.
- Use byte length for storage limits and grapheme clusters for user-facing character limits.
- Prefer the platform encoder or serializer over hand-built escaping; it handles the edge cases you will forget.
Who Should Use This Calculator?
- ▸ Form validation and user-facing character limits.
- ▸ Content planning and localization review.
- ▸ API validation: confirm that a payload fits a byte limit before sending it.
- ▸ Database sizing: translate character limits into bytes for the actual column encoding.
- ▸ Debugging: explain mojibake, double-encoded URLs and invisible Unicode characters.
- ▸ Security review: detect homoglyphs, zero-width joiners and mixed-script identifiers.
Related Programming Calculators
Keep going — every tool below links directly into this workflow.
People Also Search For
Tap a long-tail question to jump to the matching FAQ answer.
Frequently Asked Questions (19)
Long-tail answers: each question targets a real Google search about string byte-length calculator — click to expand.
Showing 19 of 19 answers.
Why does Latin-1 show question marks?
How do I convert bytes to a Base64 size?
What does the string byte-length calculator show?
How do I verify a string byte-length calculator result?
What is a common mistake when using the string byte-length calculator?
How long is a string in UTF-8 bytes?
What is a grapheme cluster?
Does the String Byte-Length Calculator count characters or bytes?
Which Unicode version does the String Byte-Length Calculator use?
Why does the String Byte-Length Calculator show a different length from JavaScript?
Is the String Byte-Length Calculator safe for confidential text?
Why do I see a replacement character (�) in the String Byte-Length Calculator output?
Can the String Byte-Length Calculator handle emoji and combining marks?
What is the string byte-length calculator used for?
How do I read the string byte-length calculator result?
What formula does the string byte-length calculator use?
What is a common mistake when using string byte-length calculator?
How do I verify a string byte-length calculator result by hand?
Does the string byte-length calculator work offline?
Resources & Authoritative References
Further reading
- Unicode — UTF-8 encoding form — The normative definition of UTF-8, code points and surrogate pairs.
- MDN — TextEncoder — How browsers encode JavaScript strings as UTF-8 bytes.
- MDN — String.length — Why JavaScript string length counts UTF-16 code units.
- RFC 4648 — Base16, Base32, Base64 — The standard alphabets, padding rules and URL-safe Base64 variant.
- WHATWG — URL standard — Percent-encoding rules used by encodeURIComponent and URL parsing.
- Python — Unicode HOWTO — A practical guide to code points, encodings and normalization.
Authoritative sources
Was this calculator helpful?
Last updated: October 2026 · Free forever · No sign-up · Part of Programming Calculators at Atlascalcs.com · All math runs in your browser