Sitemap
Samir Kaushik

Samir Kaushik

Understanding Network Byte Order

1 min readMay 25, 2026

--

When computers communicate over a network, they exchange raw bytes.

For example, consider this 32-bit number:

[
0x12345678
]

It consists of 4 bytes:

12 34 56 78

Some systems store it in memory like this:

12 34 56 78

This is called big-endian (most significant byte first).

Others store it like this:

78 56 34 12

This is called little-endian (least significant byte first).

Most modern computers (x86/AMD64) are little-endian.

Why This Matters in Networking

Suppose a little-endian machine sends a number directly over the network.

Get Samir Kaushik’s stories in your inbox

Join Medium for free to get updates from this writer.

The receiver may interpret the bytes in a different order and read a completely different value.

To avoid this confusion, networking protocols standardized one format:

Network Byte Order = Big-Endian

This means all multi-byte integers sent over networks must use big-endian format, regardless of the machine’s native architecture.

The Conversion Functions

In low-level networking code, you’ll often see functions like:

htons() // host to network short
htonl() // host to network long
ntohs() // network to host short
ntohl() // network to host long

Example:

server.sin_port = htons(8080);

These functions convert numbers between the machine’s native format and network byte order.

Important Detail

The network itself does not understand integers.

It only transports bytes.

Network byte order is simply an agreement about how those bytes should be arranged so every machine interprets them consistently.

In One Sentence

Network byte order is the standardized big-endian format used to represent multi-byte integers during network communication.

--

--