Data Representation & Number Systems

endianness

/ EN-dee-an-ness /

When a value is bigger than one byte — say a 4-byte integer — the computer must store its bytes in memory in some order, and there are two sensible choices. Endianness is which order a machine picks. The name comes, as a joke, from Gulliver's Travels, where two factions went to war over whether to crack a boiled egg at its big end or its little end — a fight over a difference that does not really matter, except that here both sides exist and you must know which you are dealing with.

Take the 4-byte hex value 0x12345678. In big-endian order the most significant byte (0x12) is stored first, at the lowest address, reading left-to-right like we write numbers: 12 34 56 78. In little-endian order the least significant byte (0x78) is stored first, so the bytes appear reversed in memory: 78 56 34 12. Big-endian feels natural to humans and is the traditional order for network protocols (hence 'network byte order'); little-endian is what most desktop and laptop processors, including the x86 family, use internally. Within a single machine this is completely invisible — the processor reads its own bytes back correctly, so a program never has to think about it.

Endianness only bites at boundaries: when bytes cross between machines of different endianness, or are written to a file or sent over a network and then read by another system. If a little-endian machine sends the raw bytes of an integer and a big-endian machine reads them naively, 0x12345678 becomes 0x78563412 — a wildly wrong number. That is why file formats and network protocols specify a fixed byte order and why portable code converts to and from it explicitly. The honest summary: endianness never matters inside one consistent machine, and always matters the moment data leaves it.

The 32-bit value 0x12345678 stored at an address: big-endian memory holds 12 34 56 78, little-endian holds 78 56 34 12. Send the raw bytes between mismatched machines without converting and the number silently becomes wrong.

Big-endian stores the high byte first; little-endian stores the low byte first.

Endianness is invisible within one machine and only bites when bytes cross to a file, network, or a differently-ordered machine. Network protocols fix a byte order, so portable code must convert explicitly.

Also called
byte orderbig-endian / little-endian大端/小端