endianness
termKept in this browser · My desk
Stands for: byte order: big-endian (most significant byte first) or little-endian (least significant byte first)
The order in which a processor, a file format or a protocol lays out the bytes of a number wider than one byte: big-endian puts the most significant byte at the lowest address, little-endian the least significant.
Danny Cohen named the two orders in 1980, after the egg war in Gulliver's Travels. Internet headers are big-endian, which RFC 791 states and POSIX calls network byte order; x86-64 and most Arm systems are little-endian; IBM z is big-endian; Power, RISC-V, MIPS and SPARC can run either way, which is called bi-endian. Code converts at every boundary with htonl, ntohs and their relatives, and a missed conversion produces a valid wrong number rather than an error: port 80 written in host order on a little-endian machine is read from the wire as port 20480.
What it is. The 32-bit value 0x0A0B0C0D is stored as the bytes 0A 0B 0C 0D on a big-endian machine and 0D 0C 0B 0A on a little-endian one. POSIX defines the two: a little-endian representation has the least significant byte first, with significance increasing as the address increases, and a big-endian one the most significant byte first. Only numbers wider than a byte are affected: single bytes, ASCII text and UTF-8 look the same either way, and the order of bits inside a byte is the link layer's business, not software's (RFC 2469 records that Ethernet maps the first bit of each byte on the wire to its least significant bit, while Token Ring did the opposite).
Where it is fixed. Intel's manual calls Intel 64 and IA-32 processors little endian machines, and IBM's z/Architecture addresses a field by its leftmost, high-order byte. The Power ISA lets the operating system choose the order with one mode bit; RISC-V defines little-endian, big-endian and bi-endian variants but always stores instructions as little-endian parcels; SPARC V9 is big-endian by default with little-endian data accesses; Linux describes MIPS systems as built for one order or the other. Among formats, the Internet headers, PNG, Java class files, XDR (External Data Representation) and CBOR are big-endian; BMP and WebAssembly memory are little-endian; TIFF marks its order with II or MM, ELF with the EI_DATA byte, and UTF-16 text with a byte order mark, without which the Unicode Standard and RFC 2781 read it as big-endian while browsers, following the WHATWG Encoding Standard, take the label utf-16 to mean UTF-16LE.
Converting. The conversions are cheap and named by direction: htonl and ntohl in POSIX, htobe32 and le32toh in its newer endian.h, cpu_to_be32 in the Linux kernel, the ! and the less-than and greater-than prefixes of Python's struct. Processors carry instructions for it: BSWAP and MOVBE on x86, LOAD REVERSED on IBM z, the byte-reverse loads and stores on Power, rev8 in RISC-V's Zbb extension. To find out what a machine is, Python's sys.byteorder answers little or big, and lscpu prints a Byte Order line.
Why it matters. Neither order wins on merit: Cohen's memo lists what serial comparators prefer and what serial adders prefer, and concludes that it is more important to agree upon an order than which order is agreed upon. RISC-V's designers chose little-endian because it dominates commercially, and kept big-endian variants because IP networking works on big-endian data; RFC 4506 admits that XDR's single big-endian order is unfair to little-endian machines, and argues that one order means no protocol is needed to read the data. The real cost is the conversion at each boundary and the bugs when one is missed: a port or an address loaded raw, UTF-16 decoded in the wrong order, a hash taken over raw bytes. The Linux bonding driver hashes raw address bytes, so an x86-64 server and an s390x guest compute different hashes for the same flow, and with three, five, six or seven members they often send it over different links.
Also known as: byte order, big-endian, little-endian, bi-endian, network byte order, host byte order, byte swap, byteswap, ordem de bytes, ordem dos bytes, ordem de rede
Sources
- Danny Cohen, IEN 137, 'On Holy Wars and a Plea for Peace', 1 April 1980 (read 2026-11-08): the names Little-Endians and Big-Endians, consistent orders, the arguments for each, agreeing on an order matters more than which
- The Open Group Base Specifications Issue 8 (POSIX.1-2024), be16toh (read 2026-11-08): the definitions of little-endian and big-endian representation; network byte order is big-endian
- POSIX.1-2024, 4.13 Host and Network Byte Orders (read 2026-11-08): network byte order and host byte order; htonl, htons, ntohl and ntohs
- RFC 791, Internet Protocol, Appendix B (read 2026-11-08): the most significant octet is transmitted first
- RFC 2469, A Caution On The Canonical Ordering Of Link-Layer Addresses (read 2026-11-08): Ethernet and Token Ring bit order
- Intel 64 and IA-32 Architectures Software Developer's Manual, volume 1, 253665-084US (read 2026-11-08): little endian machines; BSWAP and MOVBE
- IBM z/Architecture Principles of Operation, SA22-7832-13 (read 2026-11-08): a group of bytes addressed by its leftmost byte; LOAD REVERSED
- OpenPOWER Foundation, Power ISA Version 3.1C (read 2026-11-08): the Endian mode specified by the operating system; byte-reverse instructions
- RISC-V Instruction Set Manual, unprivileged, intro.adoc (read 2026-11-08): little-endian, big-endian and bi-endian variants; little-endian instruction parcels; why little-endian was chosen
- SPARC International, The SPARC Architecture Manual, Version 9 (read 2026-11-08): big-endian by default, little-endian data accesses
- The Linux kernel, arch/mips/Kconfig (read 2026-11-08): MIPS machines configured for either byte order
- RFC 4506, XDR: External Data Representation Standard (read 2026-11-08): one big-endian byte order, and why
- The Unicode Standard 18.0.0, chapter 3, D98 (read 2026-11-08): the UTF-16 encoding scheme is big-endian when there is no byte order mark
- WHATWG Encoding Standard (read 2026-11-08): the label utf-16 names UTF-16LE
- The Linux kernel, drivers/net/bonding/bond_main.c (read 2026-11-08): the transmit hash over raw address bytes
- Python documentation, sys.byteorder (read 2026-11-08)
- Python documentation, struct (read 2026-11-08): Intel x86, AMD64 (x86-64) and Apple M1 are little-endian; IBM z is big-endian; the ! prefix is network order
- Debian wiki, ArchitectureSpecificsMemo: the endianness of each Debian port (read in a browser on 2026-11-08: the site refuses automated reads)
- util-linux, sys-utils/lscpu.c (read 2026-11-08): the Byte Order line
- The Linux kernel, include/linux/byteorder/generic.h (read 2026-11-08): cpu_to_be32 and the other conversions
- RISC-V Instruction Set Manual, zbb.adoc (read 2026-11-08): rev8 reverses the byte order of a register
- W3C, PNG Specification, Third Edition, 7.1 (read 2026-11-08): integers in network byte order
- Oracle, The Java Virtual Machine Specification, Java SE 25, chapter 4 (read 2026-11-08): multibyte data items in big-endian order
- RFC 8949, CBOR (read 2026-11-08): multi-byte values in network byte order
- Microsoft Learn, BITMAPFILEHEADER (read 2026-11-08): bfType must be 0x4d42, the ASCII string BM
- WebAssembly 3.0 specification, instructions (read 2026-11-08): memory values read and written in little endian byte order
- Aldus, TIFF Revision 6.0, 1992, as hosted by the ITU (read 2026-11-08): II and MM; readers must handle both
- System V ABI, generic ABI, ELF header (read 2026-11-08): EI_DATA, ELFDATA2LSB and ELFDATA2MSB
- RFC 2781, UTF-16, an encoding of ISO 10646 (read 2026-11-08): text without a byte order mark should be read as big-endian