Oh MyUtils

Byte Counter - String Byte Size Calculator Online

Calculate the byte size of strings in UTF-8, UTF-16, ASCII, ISO-8859-1, and Base64 encodings. Check against common size limits — 100% client-side, no data sent to server.

Input
Characters
0
UTF-8
0 bytes
UTF-16
0 bytes
ASCII
0 bytes
ISO-8859-1
0 bytes
Base64 Encoded
0 bytes

Frequently Asked Questions

What is a byte counter?

A byte counter calculates the exact number of bytes a string occupies in various character encodings (UTF-8, UTF-16, ASCII). Unlike character count, byte count reflects the actual memory or storage size of text data.

Why is byte count different from character count?

In multi-byte encodings like UTF-8, characters beyond ASCII require 2-4 bytes. For example, a Chinese character takes 3 bytes in UTF-8 but counts as 1 character. Emoji can take 4 or more bytes. This matters for storage limits, API payloads, and database columns.

Is my data secure? Does it leave my browser?

All calculations are performed 100% client-side using the browser's built-in TextEncoder API. Your text never leaves your browser and is never sent to any server.

What is the difference between UTF-8 and UTF-16?

UTF-8 uses 1-4 bytes per character (efficient for ASCII-heavy text). UTF-16 uses 2 or 4 bytes per character (JavaScript's internal encoding). For English text, UTF-8 is smaller. For CJK text, they are similar. UTF-16 is relevant when working with JavaScript string internals, Windows APIs, or Java/C# string lengths.

How is Base64 encoded size calculated?

Base64 encoding converts every 3 bytes of input into 4 ASCII characters. The formula is ceil(byteLength / 3) * 4. This results in approximately 33% size overhead, which is important when embedding data in URLs, JSON payloads, or data URIs.

What are common byte size limits developers encounter?

Common limits include: HTTP cookies (4 KB), URL length (2,048 chars), HTTP headers (8 KB), localStorage (5 MB per origin), SMS messages (160 chars GSM-7 / 70 chars Unicode), and database VARCHAR columns (varies by DB engine).

Code Examples

// UTF-8 byte size using TextEncoder
function getUtf8ByteSize(str) {
  return new TextEncoder().encode(str).byteLength;
}

// UTF-16 byte size (JavaScript internal encoding)
function getUtf16ByteSize(str) {
  return str.length * 2; // Each code unit = 2 bytes
}

// Base64 encoded size from UTF-8
function getBase64Size(str) {
  const utf8Len = new TextEncoder().encode(str).byteLength;
  return Math.ceil(utf8Len / 3) * 4;
}

// Usage
const text = 'Hello, World! 안녕하세요 🌍';
console.log('Characters:', [...text].length);     // 19
console.log('UTF-8 bytes:', getUtf8ByteSize(text)); // 33
console.log('UTF-16 bytes:', getUtf16ByteSize(text)); // 40
console.log('Base64 size:', getBase64Size(text));   // 44

Related Tools