The concept of endianness is fundamental to ensure the integrity and efficiency of data transmission. The choice between these formats, which defines the order of bytes in memory, has a crucial function in the interpretation of data between systems.
In this tutorial, we’ll first explore the concept of endianness. Then, we’ll understand the standardization of the big-endian in the TCP/IP protocol and its advantages.
Computers use groups of binary bits of different sizes to store data. Bytes are the main structure, i.e., a byte comprises 8 bits and represents the smallest data group with an address in memory.
An isolated computer operates correctly because of the normalization applied when processing its data. However, we can have a communication problem when processing data created by another computer that doesn’t use the same standard. To solve this, it’s essential to define a standard format between these devices with an indicative header.
Endianness denotes the order in which bytes are allocated in computer memory. For a better understanding of the concept of endianness, we can make an analogy to the writing direction of languages, varying from left to right and right to left.
There are two predominant forms of endianness: big-endian, which allocates the most significant byte in the smallest memory address and the least significant byte in the largest, and; little-endian, which allocates the least significant byte in the smallest memory location and the most significant byte in the largest.
Let’s consider that we must store the value 0xABCD1234 in hexadecimal notation. The figure below illustrates the storage of this value in both cases:
3. Standardization for Big-Endian
Directly, TCP/IP, like most protocols, uses big-endian encoding due to the standardization done by RFC 1700. Based on Cohen’s publication “On Holy Wars and a Plea for Peace” this RFC establishes that numbers must be expressed in decimal and represented in big-endian order.
In the publication, Cohen discusses the debates around the choice of an endianness format and argues that adopting the big-endian format could bring advantages in simplicity and consistency. However, it also discusses the advantages and disadvantages of both options in different contexts.
The advantages of adopting big-endian include the following factors.
3.1. Historical Precedence
Big-endian coding was part of the original design of the ARPANET, the precursor to today’s Internet. In addition, in some older architectures, such as the IBM System/360, big-endian was the predominant format.
3.2. Ease of Protocol Implementation
Big-endian encoding simplifies the implementation of network protocols, as there’s no need for data conversion.
In other words, the order in which the header and data are transmitted mirrors the order in which they’re written and read in English. As well as simplifying the development itself, it also makes the process of debugging the code less difficult. This reduces the probability of bugs or interoperability problems.
3.3. Consistency with Mathematical Conventions
The byte order in big-endian aligns with the way we write numbers (e.g., from left to right), which makes it more intuitive. Making it easier, for example, the interpretation of IP addresses.
It’s important to note that different computing contexts can favor different endianness. For example, although big-endian is prevalent in network protocols, little-endian is common in processor architectures such as x86, ARM, and RISC-V. Regarding file formats, you can adopt both orders, a combination, or signal the order throughout the file.
In this article, we discuss some aspects of why TCP/IP uses big-endian encoding.
In short, after extensive discussion, RFC 1700 published this recommendation. Therefore, big-endian’s influence extends beyond TCP/IP, as it’s widely used in Internet standards, ensuring consistent byte order across various networking layers. This made the protocols easier to implement and maintain, as well as made them more consistent.
However, the context significantly influences the choice between big-endian and little-endian. So, it’s important to analyze the advantages of each format according to the chosen scenario.