UNICODE TEXT

Inspecting a UTF-8 byte-order mark that remains in decoded text

A leading U+FEFF can survive decoding and sit invisibly in front of the first visible character. This guide decodes the bytes EF BB BF 41 and uses code points to show what the decoder preserved.

A character you cannot see

Some text values start with a character that no editor displays. It occupies a position in the string, it counts toward the length, and it can make two values that look identical compare as different. The usual culprit is U+FEFF, which Unicode defines as the byte order mark when it appears at the start of a stream. In UTF-8 it is written as the three bytes EF BB BF. The decoder on this site keeps it. The text that comes out of EF BB BF 41 therefore has two scalars, the invisible one and the capital letter A. Because the first scalar draws nothing, only an inspection of code points, not a visual check, can reveal it. In practice, the first symptom is usually a comparison that fails for no visible reason, and the cause turns out to be the prefix.

The bytes behind the default case

Feed the hexadecimal bytes EF BB BF 41 to the UTF-8 byte converter in decode mode. The last byte, 41, is the ASCII code for A. The first three form a single three-byte sequence. In binary, EF is 11101111, BB is 10111011 and BF is 10111111. The leading 1110 announces a three-byte character, and the continuation bytes each begin with 10. Stripping those marker bits leaves 1111, 111011 and 111111, which joined give 1111111011111111, the hexadecimal value FEFF. So the decoder returns U+FEFF followed by A. The first case below the article shows exactly this: the output text begins with an invisible character that was retained. Since only the byte sequence EF BB BF produces this scalar in UTF-8, spotting those three bytes at the start of a hex dump is enough to identify the mark without running any decoder.

Making the prefix visible

Pass the decoded text to the Unicode converter in encode mode, and it lists each scalar as U+ followed by hexadecimal digits. For the decoded value it returns U+FEFF U+0041. Two scalars appear where the eye sees one. A control input of the plain letter A returns only U+0041, which is the third case. Comparing the two outputs settles the question without guessing. This step is the practical lesson of the guide: when two strings look equal and compare unequal, list their code points. The difference is often an invisible character at one end, and the list shows it at once even when fonts and editors hide it completely. The listing also guards against the opposite mistake of assuming a hidden character exists. If the output shows only U+0041, the string is clean and the problem lies elsewhere.

What U+FEFF is for

The Unicode Standard assigns U+FEFF the name zero width no-break space, and it also uses the character as a byte order mark. In UTF-16 and UTF-32, where bytes can be ordered two ways, a leading U+FEFF tells a reader the order: FE FF means big-endian and FF FE means little-endian for UTF-16. UTF-8 has only one byte order, so the mark is not needed for that purpose. The standard permits it but does not require or recommend it. Some programs add it anyway, as a signal that a file is UTF-8 and not an older single-byte encoding. That use is common in files created by certain Windows tools, and it is the reason the three bytes EF BB BF turn up at the front of text files.

How a stray prefix breaks things

The invisible character causes trouble wherever a program expects the first visible character to be the first character in the string. A comma-separated file whose first header is id may arrive with the header read as U+FEFF followed by id, so a lookup for id finds nothing. A script that starts with a shebang line may fail if the three bytes come before the number sign. A JSON parser may reject a document that starts with them, and the JSON specification in RFC 8259 says implementations must not add one, though they may ignore it. Configuration files, manifest files and key-value dumps are other typical victims. The error message rarely mentions the prefix, which makes the problem hard to find without a code point listing. The visible symptom is often a lookup that fails for a key that plainly exists, or a header row whose first name appears to have an extra character before it.

The case for keeping or removing it

Whether the prefix should stay depends on the file format and on the consumer. Some spreadsheet applications use it to recognize that a comma-separated file is UTF-8, and without it they may show accented letters wrongly. Many command-line tools and parsers expect none. A decoder that preserves the mark leaves the choice to you, which is the safest default because no information is lost. This tool does not remove it. If a downstream system needs a clean string, apply a deliberate cleanup step and keep the original bytes available. Silent removal in a decoder would make round trips lossy, and it would hide the fact that the source file carried a mark at all.

Another example: an accented letter

Decoding the bytes C3 A9 returns the single letter é. Encoding it for inspection returns U+00E9. These are ordinary results with no leading mark. Now put the three prefix bytes in front, EF BB BF C3 A9, and the decoder returns U+FEFF followed by é, while the code point listing shows U+FEFF U+00E9. The visible output looks the same as before, but the string is longer by one. Counting characters in a database column or enforcing a length limit on such a string gives a result one higher than a reader would expect. Any validation that cares about the first character or the length deserves a quick check for the prefix when the source is a file. The same counting issue affects length limits in forms and database columns, where a limit of one character per field would reject a value that seems to fit.

Other characters that hide

The byte order mark is the best-known invisible character, but not the only one. The zero width space U+200B, the zero width joiner U+200D and the soft hyphen U+00AD all draw nothing in common contexts. Non-breaking space U+00A0 looks like an ordinary space and is a frequent cause of comparison failures. The code point listing is the same remedy in each case. List the scalars and look for anything outside the expected range. For a value that should contain only ASCII letters and digits, every scalar above U+007F is suspect. The converter shows them all without altering them, so it works as a read-only inspector of what the string really contains. Each of these has a legitimate role in some writing systems or layouts, so removing them wholesale can damage real text. Inspect first, then decide which ones are mistakes.

Where the mark comes from

A byte order mark in a UTF-8 file is written by software, not by the author. Many editors offer a save option named UTF-8 with BOM, and some tools choose it by default. Windows PowerShell 5.1, for instance, writes the mark when you ask for UTF-8 output through certain commands, which is why files created that way can carry it into a pipeline that never expected it. Exports from some spreadsheet programs add it so that accented letters open correctly in the same program. Because the origin is usually a setting and not the content, the same text saved by two tools may differ by exactly these three bytes. Checking the first bytes of a suspicious file with a hex viewer takes seconds and settles whether a mark is present.

Counting bytes and characters

The prefix changes both measurements of a text. A file that holds only the letter A is one byte long, because A is the single byte 41. With a mark in front, it is four bytes: EF BB BF 41. In characters the same pair is one and two. A tool that reports a length of 2 for what looks like a single-letter string is a strong hint that something invisible is present. The extra three bytes can also upset checksums, signatures and byte-for-byte comparisons between files that otherwise contain the same text. If two files differ in size by exactly three bytes and the visible text matches, the mark is the first suspect, and the code point list on this page can confirm it for the decoded text.

Comparison and trimming behave differently

Programming languages disagree about whether U+FEFF counts as whitespace. In JavaScript, the trim method on strings removes it from the ends, because the language definition includes U+FEFF among its whitespace characters. In Python, the strip method does not remove it unless you pass the character explicitly. So the same cleanup step succeeds in one environment and silently does nothing in another. A direct comparison of the string A with the two-scalar string that starts with U+FEFF returns false everywhere, since the strings differ in length and content. When behavior seems inconsistent between systems, listing the code points on both sides is more reliable than reasoning about which trimming rule applies.

Scope of the check

The worksheet tests the behavior of two tools on one small input. It does not claim anything about how a given application, operating system or file format handles the mark, and it does not recommend a policy. A decoder round trip tells you what this decoder does, nothing more. When a file is involved, keep the original bytes, because they are the only complete record. Apply any cleanup as an explicit separate step with a documented reason, and verify the result by listing code points again. If the receiving system has a specification, follow what it says about the byte order mark, since the same three bytes can be required in one context and rejected in another.

Reproduce the checks

Decode with the prefix

Open the Utf8 Byte Converter and enter:

Calculation mode
decode
Text or encoded input
EF BB BF 41

Expected output:

Hex

A

The first scalar is retained even if it appears invisible.

Inspect the decoded scalars

Open the Unicode Converter and enter:

Calculation mode
encode
Text or encoded input
A

Expected output:

Code points

U+FEFF U+0041

The visible A is not the whole sequence.

Ordinary A control

Open the Unicode Converter and enter:

Calculation mode
encode
Text or encoded input
A

Expected output:

Code points

U+0041

This control has no leading marker.

References and implementation scope

The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.

Sources

Related tasks