Multi-byte data (16-bit, 32-bit, 64-bit numbers) must be stored in memory as individual bytes. But which byte goes at the lowest memory address — the most significant or least significant byte?
Endianness defines the byte order used to store multi-byte data in memory: Big Endian puts the Most Significant Byte first; Little Endian puts the Least Significant Byte first.
- A 32-bit number like
0x12345678has 4 bytes: 0x12 (MSB), 0x34, 0x56, 0x78 (LSB) - Big Endian stores:
12 34 56 78at increasing memory addresses - Little Endian stores:
78 56 34 12at increasing memory addresses - When reading multi-byte data, CPU must know the correct byte order
- Mismatch between systems causes data corruption (e.g., network data on x86)
- Big Endian: matches human reading order (easier to debug in memory dumps)
- Little Endian: more efficient for CPU arithmetic (LSB processed first on x86)
- Network protocols use Big Endian (called “network byte order”)
- Intel x86/AMD use Little Endian; some RISC chips use Big Endian
- Built from: Memory, Multi-Byte Data
- Contrasts with: Big Endian vs Little Endian — different byte orders
- Related: Network Byte Order, Memory Address
- Builds into: Data Serialization — must handle endianness when transferring data
- Endianness only matters for multi-byte data (byte-order sensitive)
- Single bytes are not affected by endianness
- Mixing systems with different endianness causes data corruption
- Some CPUs are bi-endian (can switch mode) — software must track current mode