· 4 min read
How to Find a Character's ASCII or Unicode Code
Manesh Jayawardhana
CIO & Co-founder
A database rejects a username that looks perfectly normal. A CSV import fails on a row that appears identical to the one above it. A string comparison returns false for two strings that render the same on screen.
All three have the same cause: characters are not what they look like. What you see is a glyph; what the computer stores is a number, and sometimes several bytes.
Code points and encodings are different things
This distinction causes more confusion than anything else in text handling, so it’s worth being precise.
A code point is a number that identifies a character in Unicode. The letter A is U+0041. The euro sign is U+20AC. A grinning face is U+1F600. Every character has exactly one.
An encoding decides how that number is stored as bytes. UTF-8 uses one byte for code points below 128, two for most European accented characters, three for most of the rest of the world’s scripts, and four for emoji and less common symbols.
ASCII is the first 128 code points, and UTF-8 was deliberately designed so that those first 128 encode as a single byte identical to their ASCII value. That backward compatibility is why plain English text is valid in both, and why the difference stays invisible until someone types an emoji.
Why people get stuck here
- Length means different things. JavaScript’s
string.lengthcounts UTF-16 code units, so an emoji reports 2. Python counts code points, so it reports 1. A databaseVARCHAR(10)may count bytes, so it fits two emoji. - Invisible characters. Zero-width joiners, non-breaking spaces and directional marks are real code points with no visible glyph, and they break comparisons silently.
- Lookalikes. A Cyrillic а and a Latin a are different code points that render identically. This is the basis of an entire class of phishing domain.
- Mojibake. Text decoded with the wrong encoding produces the familiar ’ garbage, which is a UTF-8 sequence read as Latin-1.
What good character inspection shows
The code point and the byte count together
The code point identifies the character; the byte count tells you what a length-limited field will actually do with it. You need both to debug a truncation problem.
The invisible ones
Any tool worth using should reveal characters that have no glyph. A trailing non-breaking space is invisible in every editor and fatal to an exact-match lookup.
UTF-16 units where relevant
If your stack is JavaScript, Java, or C#, string length is measured in UTF-16 units, and characters above U+FFFF count as two. That’s why an emoji can break a character limit that looked generous.
| Character | Code Point | UTF-8 Bytes | UTF-16 Units |
|---|---|---|---|
| A | U+0041 | 1 | 1 |
| é | U+00E9 | 2 | 1 |
| € | U+20AC | 3 | 1 |
| 😀 | U+1F600 | 4 | 2 |
Common mistakes to avoid
- Sizing a database column in characters when the engine counts bytes.
- Comparing user input without normalising — the same accented letter has both a single-code-point form and a letter-plus-combining-mark form.
- Stripping “non-ASCII” characters as a cleanup step, which mangles every name that isn’t English.
- Assuming a character limit in your UI matches the one in your storage layer.
- Debugging a mismatch by staring at the rendered text, which is exactly what hides the problem.
How to do it with Char to ASCII
The Char to ASCII tool converts characters to code points and back, in your browser.
- Paste the characters you want to inspect — including the string that’s failing.
- Choose decimal, hex, or both.
- Read the byte counts alongside, since that’s what a fixed-width column is measuring.
- Look for code points you didn’t expect: zero-width characters, non-breaking spaces, or a lookalike from another script.
The Unicode character database is the authoritative reference for what any given code point is. Other encoding tools are in the tools directory.
Frequently asked questions
Why do emoji count as two characters in some systems?
Because those systems count UTF-16 code units. Characters above U+FFFF need a surrogate pair — two units — so JavaScript reports a length of 2 for a single emoji.
Is ASCII the same as Unicode?
ASCII covers code points 0 to 127, and Unicode keeps those first 128 identical while extending far beyond them. That deliberate overlap is why plain English text is valid in both.
How do I find invisible characters in my text?
Convert it to code points. Zero-width joiners, non-breaking spaces and directional marks all have real code points and no glyph, so the conversion is the only way to see them.
Final thought
When two strings look identical and compare unequal, stop reading the text and start reading the code points. The difference is always there — it just doesn’t have a picture.