Big Endian vs Little Endian — What's the Difference?

These describe the byte order used to store multi-byte numbers in memory: big-endian stores the most significant byte first, while little-endian stores the l...

Published November 23, 2026

Endianness is the order bytes of a multi-byte number are stored in memory. Big-endian stores the most significant byte first; little-endian stores the least significant byte first (used by x86 and ARM in practice).

The concept

The 32-bit number 0x12345678 is stored as 12 34 56 78 in big-endian and 78 56 34 12 in little-endian.

It matters when reading binary files, network protocols (network byte order is big-endian) and sharing data between different architectures.

0x12345678 in memory

address 0 1 2 3
big 12 34 56 78
little 78 56 34 12

Practical examples

JavaScript DataView

const b = new DataView(new ArrayBuffer(4))
b.setUint32(0, 0x12345678, false)  // big-endian
b.setUint32(0, 0x12345678, true)   // little-endian

Python struct

import struct
struct.pack('>I', 0x12345678)  # big-endian
struct.pack('<I', 0x12345678)  # little-endian

Detect host endianness

new Uint8Array(new Uint32Array([1]).buffer)[0] === 1  // true = little-endian

Common mistakes

  • Forgetting to convert to network byte order.
  • Parsing binary formats with the wrong endianness.
  • Assuming all CPUs match yours.

Key takeaways

  • Byte order of multi-byte values.
  • Network order is big-endian.
  • Specify endianness when serialising.

FAQ

What is network byte order?

Big-endian, used in TCP/IP headers.

Does it affect text?

UTF-8 is byte-oriented, but UTF-16/32 care about it (BOM).

More General articles