文字数とバイト数の違い
- 日本語は1文字が複数バイト
- UTF-8で数える
- 制限がバイトのときに確認
「文字数」と「バイト数」は、別のものです。システムの入力欄や、データベースの制限では、バイト数が使われることがあります。文字数カウント(エントリーシート・レポート用) は、UTF-8でのバイト数も表示します。
違い
- 文字数:文字の個数。人が数える、「見える文字」の数。
- バイト数:コンピューターがデータを扱う大きさの単位。文字の種類で、1文字あたりのバイト数が違う。
UTF-8でのバイト数の目安
- 半角英数字・記号:1文字 = 1バイト
- ひらがな・カタカナ・漢字・全角記号:1文字 = 3バイト
- 一部の絵文字・珍しい漢字:4バイト
手順
- 「文章」の欄に、文章を貼り付けます。
- 「バイト数(UTF-8)」の欄を見ます。
- 制限のバイト数と比べます。
例
- 「Hello」→ 5文字・5バイト
- 「こんにちは」→ 5文字・15バイト
- 「Hello こんにちは」→ 11文字・21バイト(英字5+スペース1+ひらがな15)
実際の値は、ツールの表示で確かめます。
バイト数が使われる場面
- データベースの項目の長さ制限
- 古いシステムの入力欄
- SMS(ショートメッセージ)の長さ制限
- メールの件名、プログラムの文字列の制限
- ファイル名の長さ制限
全角のほうが多く数える
同じ文字数でも、日本語は、英語の約3倍のバイト数です。バイト数で制限がある場合は、日本語は、文字数が少なくなります。
例
「100バイトまで」の入力欄。日本語なら、約33文字まで。英数字なら、100文字まで。
つまずきやすい点
- 制限が文字数かバイト数か分からない:入力欄の説明を確認する。
- Shift_JISでは数が違う:Shift_JISでは、日本語は1文字2バイトです。このツールはUTF-8です。
- 絵文字で数が増える:絵文字は4バイトの場合があります。
よくある質問
バイト数と、ファイルの容量は同じですか?
文字だけのテキストファイルなら、ほぼ同じです。
まとめ
文字数とバイト数は別。制限がバイトなら、日本語は1文字約3バイトで計算しましょう。
文字数カウント(エントリーシート・レポート用)を使う(無料)あわせて使えるツール
- 文章の改行を消す・整える:PDFなどからコピーした文章の改行を整えます。
- 全角・半角、ひらがな・カタカナを変換する:全角・半角、ひらがな・カタカナを変換します。
- PDFから文字を抜き出す:PDFの文字を取り出して、コピーまたは保存できます。
同じツールの、ほかの解説
Characters vs. Bytes
- Japanese characters use several bytes
- Counted in UTF-8
- Check when the limit is in bytes
"Character count" and "byte count" are different things. System input boxes and database limits sometimes use bytes. Character Counter (for Applications and Reports) also shows the byte count in UTF-8.
The difference
- Character count: the number of characters. The number of "visible characters" a person counts.
- Byte count: the unit in which a computer handles data size. The bytes per character depend on the kind of character.
Guide to UTF-8 bytes
- Half-width letters, digits and symbols: 1 character = 1 byte
- Hiragana, katakana, kanji and full-width symbols: 1 character = 3 bytes
- Some emoji and rare kanji: 4 bytes
Steps
- Paste text in the "Text" field.
- Look at the "Bytes (UTF-8)" field.
- Compare with the byte limit.
Examples
- "Hello" → 5 characters, 5 bytes
- "こんにちは" → 5 characters, 15 bytes
- "Hello こんにちは" → 11 characters, 21 bytes (5 + 1 + 15)
Check the actual value in the tool's display.
Where bytes are used
- Length limits on database fields
- Input boxes of older systems
- Length limits of SMS (short messages)
- Email subjects, limits on strings in programs
- Length limits on file names
Full-width counts more
For the same number of characters, Japanese takes about three times the bytes of English. When there is a byte limit, Japanese allows fewer characters.
Example
An input box with "up to 100 bytes". In Japanese, about 33 characters. In letters and digits, 100 characters.
Common stumbling blocks
- Unsure whether the limit is characters or bytes: check the input box's description.
- Shift_JIS counts differently: in Shift_JIS, Japanese is 2 bytes per character. This tool uses UTF-8.
- Emoji increase the count: emoji can be 4 bytes.
Frequently asked questions
Are bytes and file size the same?
For a text-only file, nearly the same.
Summary
Characters and bytes are separate. If the limit is in bytes, calculate Japanese at about 3 bytes per character.
Use "Character Counter (for Applications and Reports)" (free)Tools that go well with this
- Remove and Tidy Line Breaks in Text: Tidy line breaks in text copied from PDFs and elsewhere.
- Convert Full-Width, Half-Width, Hiragana and Katakana: Convert full-width/half-width and hiragana/katakana.
- Extract Text from PDF: Pull the text out of a PDF to copy or save.