Skip to content
uencoder

BOM

The BOM (byte order mark) is the Unicode character U+FEFF, placed at the start of a text stream to indicate the encoding form and byte order.

Purpose

It signals big- or little-endian byte order in UTF-16/UTF-32, and serves as an encoding signature in UTF-8 (even though UTF-8 has no byte-order ambiguity).

Mechanism

U+FEFF is rendered into bytes by the encoding form: EF BB BF in UTF-8, FF FE in UTF-16LE, and FE FF in UTF-16BE. A decoder reads the first few bytes and matches them against known BOMs to determine the encoding. U+FEFF itself is a zero-width no-break space, which is why it can double as a signature.

Use cases

  • Automatic text file encoding detection
  • Cross-platform text exchange
  • Encoding markers for CSV/TSV files
  • Encoding of database export files

Examples

  • Input
    UTF-8 BOM
    Output
    EF BB BF

    The first three bytes of a file

Common errors

A UTF-8 BOM being rejected by a JSON parser (RFC 8259 forbids it)
Do not use a BOM in JSON files

Related terms

Related tools

References