Network packets are the fundamental units of data transmitted across networks, and understanding their structure is key to understanding how the internet works.
Let’s see a packet in action. Imagine you’re sending a simple HTTP GET request to a web server.
GET /index.html HTTP/1.1
Host: www.example.com
User-Agent: MyBrowser/1.0
Accept: text/html
This text looks like a single message, but when it travels across a network, it gets broken down and wrapped up into multiple packets. Each packet has a specific job.
At the most basic level, a packet consists of three main parts: the header, the payload, and framing.
The header is like the envelope of a letter. It contains all the crucial information needed to get the data from its source to its destination. This includes source and destination IP addresses, port numbers, and information about the packet’s type and sequence.
The payload is the actual data being sent. In our HTTP example, this would be the request itself (GET /index.html HTTP/1.1\r\nHost: www.example.com\r\n...). This data is often encrypted for security, so it might look like gibberish to anyone intercepting it.
Framing refers to the bits added at the very beginning and end of a packet that help the receiving network device recognize where a packet starts and ends. This is especially important in serial communication or when dealing with certain physical layer protocols. Think of it like the tape you use to seal an envelope.
Here’s a simplified view of how these layers interact, using the TCP/IP model as an example:
- Application Layer (e.g., HTTP): Your request (
GET /index.html...) is the raw data. - Transport Layer (e.g., TCP): TCP adds its own header to break the data into segments, add sequence numbers for reassembly, and ensure reliable delivery. This TCP header includes source and destination port numbers (e.g., port 80 for HTTP).
- Example TCP Header Segment (simplified):
[Source Port: 51234][Dest Port: 80][Sequence Number: 123456789][Ack Number: 987654321]...
- Example TCP Header Segment (simplified):
- Internet Layer (e.g., IP): IP takes the TCP segment and adds its header, including the source and destination IP addresses. The combination of the IP header and the TCP segment is called an IP packet.
- Example IP Header Segment (simplified):
[Version: 4][Protocol: 6 (TCP)][Source IP: 192.168.1.100][Dest IP: 172.217.160.142]...
- Example IP Header Segment (simplified):
- Link Layer (e.g., Ethernet): The IP packet is then encapsulated into a frame for transmission over the local network. This adds a MAC address header (for devices on the same network) and a trailer for error checking.
- Example Ethernet Frame (simplified):
[Preamble][SFD][Dest MAC: 00:1A:2B:3C:4D:5E][Source MAC: 00:AA:BB:CC:DD:EE][EtherType: 0x0800 (IPv4)][IP Packet][FCS]...
- Example Ethernet Frame (simplified):
Each layer adds its own header and potentially a trailer, creating a nested structure. When the packet arrives at its destination, these layers are stripped off in reverse order, allowing the original data to be reassembled and delivered to the correct application.
The most surprising true thing about network packets is that the "payload" of one layer is often the "data" that the next layer encapsulates, meaning a packet header itself can be part of the payload for the layer above it. For instance, the entire TCP segment (including its header) becomes the payload of the IP packet.
This encapsulation process is what allows different network protocols to coexist and interoperate. An HTTP request can be sent over TCP, which can be sent over IP, which can be sent over Ethernet, and each layer only needs to understand its immediate neighbors.
The next concept you’ll likely encounter is how these packets are routed across complex networks using routers and routing tables.