Text encoding

BOM (Byte Order Mark)

One invisible character at the start of a file, U+FEFF, and the very specific ways it breaks JSON, scripts, and string comparisons.

What it is

A Byte Order Mark is the Unicode character U+FEFF, placed at the very start of a file or text stream. It has no visible glyph — in a normal editor it renders as nothing at all — but it's still a real character occupying a real position in the string.

Why it exists

Some Unicode encodings — UTF-16 and UTF-32 — store each character using more than one byte, and those bytes can be ordered two different ways ("big-endian" or "little-endian") depending on the system that wrote the file. The BOM's original job was to sit at the front of the file and signal which byte order was used, so a reading program could decode the rest correctly.

Why it still shows up in UTF-8 files

UTF-8 doesn't have a byte-order ambiguity to resolve — each character is encoded the same way regardless of system. A BOM is technically meaningless in UTF-8. But some tools, most notably Windows Notepad and a number of older editors, still prepend a BOM to UTF-8 files anyway, using it as an informal "this file is UTF-8, not some legacy encoding" signal. Most modern software ignores it safely. Some doesn't.

What it actually breaks

  • JSON parsing — a BOM before the opening { is not valid JSON syntax, and some parsers will throw an error rather than silently skip it.
  • Shebang lines — if a BOM precedes #!/usr/bin/env python at the top of a script, some interpreters fail to recognize the shebang at all.
  • String comparison — two strings that look identical on screen won't be === equal if one has a leading BOM and the other doesn't. This is a common source of "why doesn't this if-statement work" bugs.
  • Rendering — misinterpreted BOM bytes sometimes appear as the mangled character sequence  at the start of a displayed page or file.

How to find and remove one

Because it's invisible, a BOM is easy to carry around for a long time without noticing. Paste suspect text into the invisible character finder — it flags a leading BOM explicitly with its code point, and the cleaned output removes it.

Source

BOM is defined as part of the Unicode Standard, maintained by the Unicode Consortium.

Related

Zero-Width Space Invisible Character Finder

Back to the full glossary — 200 terms covering case conversion, style guides, and text tools.