What is the difference between big endian and little endian byte ordering?
Endianness is the order a multi-byte value's bytes are stored: big-endian puts the most-significant byte at the lowest address, little-endian puts the least-significant byte first.
* The same 4-byte value 0x01234567, byte by byte: big-endian stores the MSB (01) at the lowest address, little-endian stores the LSB (67) first. *
Endianness only matters for values wider than one byte, since a single byte has no internal order. It is a property of the CPU, so the very same bytes read from a file or the network can decode to different numbers on different machines. Big-endian stores the most significant byte first (it reads "left to right" like we write numbers); little-endian stores the least significant byte first (so a memory dump looks "backwards").
For value 0x01234567 at address 0x100:
| Address | Big Endian | Little Endian |
|---|---|---|
| 0x100 | 01 | 67 |
| 0x101 | 23 | 45 |
| 0x102 | 45 | 23 |
| 0x103 | 67 | 01 |
Who uses what:
- Big endian: Network protocols ("network byte order"), older SPARC/PowerPC, Java
- Little endian: x86, x86-64, ARM (default), most modern CPUs
Why it matters:
- Reading raw memory dumps: bytes appear "backwards" on x86
- Network programming: must convert with
htons(),ntohs()etc. - File formats: must specify endianness (or use text)
- Reverse engineering: need to know when interpreting memory
Historical origin: Named after Gulliver's Travels - wars fought over which end of an egg to crack first!
Practical example (debugging):
Memory shows: 67 45 23 01
On x86 (little-endian), this is: 0x01234567
On network/big-endian, this is: 0x67452301
Tip: "Little endian = little end first" - the small (least significant) byte comes first in memory.
Go deeper:
Endianness (Wikipedia) — big- vs little-endian, network byte order, and which architectures use each.