Course contentsShow
← Computer Science
Lesson 29 of 2,8721. Digital FoundationsFree lesson

Byte Order Marks and Endianness

Understanding BOM markers and how byte order affects multi-byte character encodings.

Byte Order Marks and Endianness

What you'll learn: How computers decide the order of bytes in multi-byte characters and what the Byte Order Mark (BOM) tells us about that order.

The Byte Order Problem

When you learned about UTF-16 and UTF-32, you saw that characters often need multiple bytes. But here's the catch: should those bytes be stored "left-to-right" or "right-to-left"? Different computer systems make different choices.

What is Endianness?

Endianness describes the order in which bytes are arranged in memory:

  • Big-endian: Most significant byte first (like reading left-to-right)
  • Little-endian: Least significant byte first (like reading right-to-left)

Analogy

Think of writing the year "2025":

  • Big-endian: 2025 (thousands first)
  • Little-endian: 5202 (ones first)

Both represent the same value, just in different orders.

The Byte Order Mark (BOM)

A BOM is a special invisible character placed at the very start of a text file to signal:

  1. Which encoding is used (UTF-8, UTF-16, or UTF-32)
  2. Which byte order to expect

For UTF-16, the BOM is the character U+FEFF:

  • In big-endian: stored as FE FF
  • In little-endian: stored as FF FE

When a program opens the file, it reads these first bytes to know how to interpret everything that follows.

Why It Matters

Without knowing the byte order, multi-byte characters could be completely misinterpreted. The BOM acts like a decoder ring, telling the program: "Read my bytes in this order."

Key Takeaway: Endianness determines byte order in multi-byte encodings, and the Byte Order Mark (BOM) is a special marker that tells programs which order was used so characters display correctly.