AiTechWorlds
AiTechWorlds
You want to send a fragile antique vase from your home in Dhaka to a friend in London. Here is how you prepare it for the journey:
First, you wrap the vase in bubble wrap — protecting the fragile contents. Then you place it in a cardboard box with your friend's address and your return address written on it. That box gets loaded into a shipping container at the port, which has a container number and routing label for the shipping company. The container is loaded onto a cargo ship with a manifest listing which port it is heading to.
At each step, something new was added around the original item. The vase never changed — only the wrapping changed. When it arrives, your friend reverses the process: ship unloads the container, container is opened to find the box, box is opened to find the bubble-wrap, bubble-wrap is unwrapped to reveal the vase.
This is exactly how network data travels. The process of adding wrappers going down the layers is called encapsulation. The process of removing them going up is called de-encapsulation.
Encapsulation solves a fundamental problem in layered architecture: each layer must be able to do its job without knowing the details of other layers.
This separation means you can change one layer without breaking others. Moving from copper Ethernet to fiber optic? Only Layer 1 changes. Switching from IPv4 to IPv6? Only Layer 3 changes. HTTP/1.1 to HTTP/2? Only Layer 7 changes.
At each layer, data has a different name based on what has been added to it:
| Layer | PDU Name | What Was Added |
|---|---|---|
| Application (7) | Data | Original payload — e.g., HTTP request |
| Transport (4) | Segment (TCP) / Datagram (UDP) | TCP/UDP header added |
| Network (3) | Packet | IP header added |
| Data Link (2) | Frame | Ethernet/Wi-Fi header + trailer added |
| Physical (1) | Bits | Converted to electrical/optical/radio signals |
Let us trace the text "Hello World" (a simple HTTP response body) as it travels down the network stack:
At the Application Layer:
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 11
Hello World
This is the raw application data — an HTTP response.
At the Transport Layer — TCP Segment:
+---------------------------+
| Source Port: 80 | ← HTTP server port
| Destination Port: 54321 | ← Client's random port
| Sequence Number: 1000 | ← For ordering
| Ack Number: 501 | ← Acknowledging client's last byte
| Data Offset: 5 | ← Header length (20 bytes)
| Flags: PSH ACK | ← Push data now, acknowledge
| Window Size: 65535 | ← Flow control
| Checksum: 0x4F2A | ← Error detection
+---------------------------+
| [ HTTP response data ] |
+---------------------------+
TCP has segmented the data and added a 20-byte header. The sequence number allows the receiver to reassemble multiple segments in the correct order.
At the Network Layer — IP Packet:
+----------------------------------+
| Version: 4 | IHL: 5 |
| Total Length: 560 bytes |
| TTL: 64 | Protocol: 6 (TCP) |
| Source IP: 203.0.113.50 | ← Web server
| Dest IP: 192.168.1.105 | ← Your computer
| Checksum: 0x8F7E |
+----------------------------------+
| [ TCP segment (header + data) ] |
+----------------------------------+
IP adds another 20-byte header. The TTL of 64 means this packet will be discarded if it passes through more than 64 routers without arriving. Protocol field (6 = TCP) tells the receiver which transport protocol to hand data up to.
At the Data Link Layer — Ethernet Frame:
+---------------------------------------------+
| Preamble: 10101010... (7 bytes + SFD) | ← Sync signal
| Dest MAC: AA:BB:CC:DD:EE:01 | ← Next-hop router
| Source MAC: 11:22:33:44:55:66 | ← Server's NIC
| EtherType: 0x0800 (IPv4) |
+---------------------------------------------+
| [ IP packet (header + TCP segment + data) ] |
+---------------------------------------------+
| FCS (Frame Check Sequence): 0xAB12CD34 | ← Error detection
+---------------------------------------------+
Ethernet adds a header (14 bytes) and a trailer (4 bytes FCS). The destination MAC is the next-hop router's MAC address, not the final destination's MAC. MAC addresses change at every hop; IP addresses do not.
At the Physical Layer:
10110110 00101101 11010011 01001010 ... (raw bits)
The frame is converted to electrical signals (copper Ethernet), light pulses (fiber optic), or radio waves (Wi-Fi) and transmitted.
| Field | Size | Purpose |
|---|---|---|
| Source Port | 16 bits | Sending application's port |
| Destination Port | 16 bits | Receiving application's port |
| Sequence Number | 32 bits | Position in the byte stream |
| Acknowledgment Number | 32 bits | Next expected byte from sender |
| Flags | 9 bits | SYN, ACK, FIN, RST, PSH, URG |
| Window Size | 16 bits | Flow control — how much data to send |
| Checksum | 16 bits | Error detection |
| Field | Size | Purpose |
|---|---|---|
| Version | 4 bits | IPv4 or IPv6 |
| TTL | 8 bits | Hop limit — prevents routing loops |
| Protocol | 8 bits | TCP (6), UDP (17), ICMP (1) |
| Source IP | 32 bits | Sender's IP address |
| Destination IP | 32 bits | Receiver's IP address |
| Checksum | 16 bits | Header error detection |
| Field | Size | Purpose |
|---|---|---|
| Destination MAC | 48 bits | Next-hop device hardware address |
| Source MAC | 48 bits | Sending device hardware address |
| EtherType | 16 bits | Payload type (0x0800 = IPv4, 0x86DD = IPv6) |
| FCS (trailer) | 32 bits | Frame error detection (CRC) |
When your computer receives the Ethernet frame:
MTU (Maximum Transmission Unit) is the largest packet size that can be transmitted without fragmentation on a given network. For Ethernet, the standard MTU is 1500 bytes.
Why 1500 bytes? It was a practical compromise when Ethernet was designed in the 1970s. Large frames mean fewer headers (more efficient) but also mean a single corrupted frame wastes more retransmission bandwidth. 1500 bytes struck a balance.
What happens when a packet exceeds the MTU?
If you ever notice video calls freezing or large file transfers failing while small pings work fine, MTU mismatch is often the culprit — especially common with VPN tunnels that add overhead headers, reducing the effective MTU.
Get this course's notes on Telegram!
Free cheat sheets, summaries & practice exercises