Network Packet Construction: A Layer-by-Layer Breakdown
When data is sent over a network, it is broken down into packets . Each packet is structured according to the OSI model or TCP/IP model , with each layer adding its own header (and sometimes a trailer ) to the data. Here’s how a packet is constructed:
1. Data Breakdown by Layer
Application Layer (Layer 7)
Data : The actual payload (e.g., an HTTP request, email, or file).
Example : The text of this message or a webpage request.
Transport Layer (Layer 4)
Header Added :
Source Port : Identifies the sending application (e.g., 54321
).
Destination Port : Identifies the receiving application (e.g., 80
for HTTP).
Sequence Number : Ensures data is reassembled in the correct order.
Checksum : Verifies data integrity.
Protocols : TCP (reliable, connection-oriented) or UDP (fast, connectionless).
Result : The data is now a segment (TCP) or datagram (UDP).
Field
Example Value
Purpose
Source Port
54321
Identifies the sending application.
Destination Port
80
Identifies the receiving application.
Sequence Number
12345
Ensures ordered delivery.
Checksum
0xABCD
Detects errors in the segment.
Header Added :
Source IP Address : The sender’s IP (e.g., 192.168.1.10
).
Destination IP Address : The receiver’s IP (e.g., 203.0.113.45
).
TTL (Time To Live) : Limits how long the packet can exist in the network (e.g., 64
).
Protocol : Identifies the transport layer protocol (e.g., 6
for TCP, 17
for UDP).
Result : The segment is now a packet .
Field
Example Value
Purpose
Source IP
192.168.1.10
Sender’s IP address.
Destination IP
203.0.113.45
Receiver’s IP address.
TTL
64
Prevents infinite looping.
Protocol
6
Indicates TCP.
Data Link Layer (Layer 2)
Header Added :
Source MAC Address : The sender’s hardware address (e.g., 00:1A:2B:3C:4D:5E
).
Destination MAC Address : The next hop’s hardware address (e.g., 00:1F:2E:3D:4C:5B
).
EtherType : Identifies the network layer protocol (e.g., 0x0800
for IPv4).
Trailer Added :
FCS (Frame Check Sequence) : Detects errors in the frame.
Result : The packet is now a frame .
Field
Example Value
Purpose
Source MAC
00:1A:2B:3C:4D:5E
Sender’s MAC address.
Destination MAC
00:1F:2E:3D:4C:5B
Next hop’s MAC address.
EtherType
0x0800
Indicates IPv4.
Conversion : The frame is converted into bits (1s and 0s) for transmission over physical media (e.g., Ethernet cable, Wi-Fi).
Result : The frame is transmitted as electrical signals, light pulses, or radio waves .
2. Packet Structure Visualization
+---------------------+
| Application Data | <--- Original data (e.g., HTTP request)
+---------------------+
| TCP/UDP Header | <--- Transport Layer
+---------------------+
| IP Header | <--- Network Layer
+---------------------+
| Ethernet Header | <--- Data Link Layer
+---------------------+
| Payload | <--- Encapsulated data from higher layers
+---------------------+
| Ethernet Trailer | <--- Data Link Layer (FCS)
+---------------------+
Encapsulation : Each layer adds its header (and trailer) as the packet moves down the stack.
Transmission : The physical layer sends the bits over the network.
Decapsulation : At the destination, each layer strips its header and processes the data, moving up the stack until the original data is reconstructed.
4. Example: Sending an HTTP Request
Application Layer : Creates an HTTP request (e.g., GET /index.html
).
Transport Layer : Adds a TCP header (e.g., source port 54321
, destination port 80
).
Network Layer : Adds an IP header (e.g., source IP 192.168.1.10
, destination IP 203.0.113.45
).
Data Link Layer : Adds an Ethernet header (e.g., source MAC 00:1A:2B:3C:4D:5E
, destination MAC 00:1F:2E:3D:4C:5B
).
Physical Layer : Transmits the bits over the network.
Destination : The process reverses—each layer removes its header and passes the data up.
Payload : The actual data being transmitted.
MTU (Maximum Transmission Unit) : The largest size a packet can be (typically 1500 bytes for Ethernet).
Fragmentation : If a packet exceeds the MTU, it is split into smaller fragments and reassembled at the destination.
6. Why Packetization Matters
Efficiency : Breaking data into packets allows multiple devices to share the network.
Reliability : Packets can take different paths and be reassembled, improving fault tolerance.
Scalability : Networks can handle varying amounts of traffic by managing packets individually.