Network Layer Overview
Host-to-Host Delivery
Read aloud is unavailable in this browser.
Bridging the Distance
When you send a message on your phone to a friend on another continent, that data traverses an astounding path. It might travel through your home Wi-Fi router, to your ISP's network, through undersea fiber-optic cables spanning thousands of kilometers, through multiple backbone routers owned by different companies in different countries, through your friend's mobile carrier, to a cell tower, and finally wirelessly to their device.
Yet from your perspective, you simply "sent a message." The complexity of routing through dozens of intermediate systems, translating between different network technologies, and navigating autonomous systems operated by competing organizations—all of this is invisible.
Host-to-host delivery is the network layer's core mission: providing the abstraction that makes two computers—anywhere in the world, connected by any combination of network technologies—appear to be directly connected. This isn't magic; it's the result of carefully designed protocols and algorithms that we'll dissect in this page.
By the end of this page, you will understand precisely how the network layer enables end-to-end communication across heterogeneous networks, the distinction between direct and indirect delivery, how source and destination hosts differ in their roles, and the end-to-end principle that shaped this design.
Understanding Host-to-Host Communication
At the data link layer (Layer 2), communication is node-to-node: a frame can only be delivered to a device directly connected on the same network segment. If Device A wants to reach Device B on a different LAN, Layer 2 alone cannot help—there's no Layer 2 path between them.
The network layer solves this by enabling host-to-host (also called end-to-end at Layer 3) communication. Two key concepts distinguish host-to-host delivery:
1. Logical Addressing Independence:
At Layer 2, devices are identified by MAC addresses that are meaningful only within a broadcast domain. Layer 3 introduces logical addresses (IP addresses) that:
- Are globally unique (or unique within an addressing domain)
- Have hierarchical structure embedding location information
- Are independent of physical network topology
2. Multi-Hop Routing:
Host-to-host delivery doesn't require a direct link between source and destination. The network layer can route packets through multiple intermediate routers (hops), each bringing the packet closer to its destination. The source doesn't need to know the complete path—it only needs to know where to send the packet next (usually its default gateway).
| Property | Node-to-Node (Layer 2) | Host-to-Host (Layer 3) |
|---|---|---|
| Scope | Single network segment/broadcast domain | Entire internetwork (global Internet) |
| Addressing | MAC addresses (flat, 48-bit, hardware-burned) | IP addresses (hierarchical, 32/128-bit, software-assigned) |
| Path | Direct link only | Multiple hops through routers |
| Source Knowledge | Must know destination's MAC address | Must know destination's IP address only |
| Routing | None—broadcast or direct delivery | Routing protocols determine path |
| Device | Switches forward based on MAC table | Routers forward based on routing table |
| Example | Ethernet frame delivery within a VLAN | IP packet from Tokyo to New York |
Host-to-host delivery is implemented using node-to-node delivery. Each hop of an IP packet is a node-to-node transmission at Layer 2. The network layer orchestrates a sequence of node-to-node deliveries to achieve host-to-host delivery. This is layering in action: the higher layer uses the lower layer as a building block.
Direct Delivery
Direct delivery occurs when the source and destination hosts are on the same IP network (same subnet). In this case, no router needs to be involved—the source can deliver the packet directly to the destination using Layer 2 mechanisms.
Conditions for Direct Delivery:
A host determines that direct delivery is possible by comparing the destination IP address with its own network address using the subnet mask:
Source Network = Source IP AND Subnet Mask
Destination Network = Destination IP AND Subnet Mask
If Source Network == Destination Network:
→ Direct Delivery
Else:
→ Indirect Delivery (via router)
Example:
Host A (192.168.1.10/24) wants to send a packet to Host B (192.168.1.25/24).
- Host A's network: 192.168.1.10 AND 255.255.255.0 = 192.168.1.0
- Destination network: 192.168.1.25 AND 255.255.255.0 = 192.168.1.0
- Networks match → Direct delivery
Direct Delivery Process:
Steps in Direct Delivery
- •Compare Networks: Source host calculates that destination is on the same network.
- •ARP Resolution: Source checks its ARP cache for destination's MAC address. If not cached, broadcasts an ARP request: "Who has 192.168.1.25?"
- •ARP Response: Destination (or ARP proxy) responds with its MAC address.
- •Frame Construction: Source creates an Ethernet frame with:
- Destination MAC: Host B's actual MAC address
- Source MAC: Host A's MAC address
- Type field: 0x0800 (IPv4) or 0x86DD (IPv6)
- Payload: The complete IP packet
- •Transmission: Frame is transmitted on the local network.
- •Reception: Host B receives the frame, verifies its MAC address matches, extracts the IP packet, and processes it.
Key Characteristics of Direct Delivery:
-
Single Hop: Only one Layer 2 transmission is needed.
-
Final Destination: The destination MAC address in the frame is the actual destination host, not a router.
-
ARP Dependency: Requires address resolution to map IP to MAC.
-
Efficiency: Minimal latency since no intermediate routing is needed.
-
Limited Scope: Only possible within a single broadcast domain (subnet).
Direct delivery is the simpler case, but most Internet communication involves indirect delivery—crossing network boundaries through routers.
In some network configurations, a router may respond to ARP requests on behalf of hosts on other networks—this is called Proxy ARP. The source thinks it's doing direct delivery, but the router intercepts and forwards the packet. While useful in specific scenarios, Proxy ARP can be confusing for network debugging and has security implications.
Indirect Delivery
Indirect delivery occurs when the source and destination hosts are on different IP networks. The source cannot deliver directly to the destination—it must send the packet to a router (the next hop), which then forwards it toward the destination.
The Fundamental Insight:
In indirect delivery, the source knows two critical things:
- The final destination IP address (embedded in the IP header)
- The next hop (the router that should receive this packet immediately)
But the source typically does not know the complete path. It relies on routers to make hop-by-hop routing decisions until the packet reaches a router on the destination's network, which then performs direct delivery.
Indirect Delivery Process:
Steps in Indirect Delivery
- •Determine Indirect Delivery: Source host calculates that destination is on a different network (network addresses don't match).
- •Find Next Hop: Source consults its routing table. For hosts, this is usually a default gateway (e.g., 192.168.1.1).
- •ARP for Router: Source uses ARP to resolve the router's IP address to its MAC address (if not cached).
- •Frame Construction: Source creates a frame with:
- Destination MAC: Router's MAC address (not the final destination!)
- Source MAC: Host's MAC address
- Payload: IP packet with final destination IP address unchanged
- •Transmission to Router: Frame is delivered to the router on the local network.
- •Router Processing: Router strips the frame header, reads the IP destination, consults its routing table, determines the next hop.
- •New Frame Creation: Router creates a new frame with new MAC addresses for the next link.
- •Repeat: Process repeats at each router until a router determines the destination is on a directly connected network → Direct Delivery.
Critical Observation: IP Addresses Stay Constant, MAC Addresses Change
This is one of the most important concepts in network layer operation:
| Header | Frame 1 (A → R1) | Frame 2 (R1 → B) |
|---|---|---|
| IP Source | 192.168.1.10 | 192.168.1.10 |
| IP Destination | 10.0.0.50 | 10.0.0.50 |
| MAC Source | Host A's MAC | R1's Port 2 MAC |
| MAC Destination | R1's Port 1 MAC | Host B's MAC |
The IP addresses identify the endpoints of the communication and remain unchanged throughout the packet's journey. The MAC addresses identify the next physical hop and change at every router.
This separation is fundamental: IP provides end-to-end identifiers; MAC provides hop-by-hop identifiers.
Network Address Translation (NAT) is an exception where IP addresses ARE modified en route. NAT rewrites source/destination IPs (and often ports) to allow multiple private hosts to share a single public IP. This violates the original end-to-end model but is ubiquitous due to IPv4 address scarcity. We'll cover NAT in detail in a later chapter.
Multi-Hop Routing in Practice
Real-world packets often traverse many routers. Let's trace a packet's journey from a home computer in London to a web server in San Francisco to understand multi-hop host-to-host delivery.
Simplified Path Example:
| Hop | Device | Network | Action |
|---|---|---|---|
| 1 | Home Router | Home LAN (192.168.1.0/24) | Receives from PC, forwards to ISP |
| 2 | ISP Edge Router | ISP Access Network | Routes toward backbone |
| 3 | ISP Core Router | UK Backbone Network | Routes toward transatlantic link |
| 4 | Transatlantic Router | Undersea Cable Entry | Routes to US |
| 5 | US Entry Router | US Backbone Entry | Routes within US backbone |
| 6-12 | Multiple Core Routers | Various ISP Networks | Route toward destination ISP |
| 13 | Datacenter Edge Router | Datacenter Network | Routes to correct server subnet |
| 14 | Top-of-Rack Switch/Router | Server VLAN | Direct delivery to web server |
What Happens at Each Hop:
-
Frame Reception: The incoming frame is received and decapsulated. The IP packet is extracted.
-
Header Processing: The router reads the destination IP address from the IP header.
-
Routing Lookup: The router consults its routing table using longest-prefix matching to find the best route to the destination network.
-
TTL Decrement: The router decrements the IP header's Time-to-Live (TTL) field. If TTL reaches 0, the packet is discarded and an ICMP Time Exceeded message is sent to the source.
-
Checksum Recalculation: The IP header checksum is recalculated (since TTL changed).
-
Next-Hop Determination: The routing table entry specifies either a next-hop router IP or an outgoing interface.
-
Frame Creation: A new Layer 2 frame is created with:
- Destination MAC: Next-hop router's MAC (or final destination's MAC if direct delivery)
- Source MAC: This router's outgoing interface MAC
- The IP packet as payload
-
Transmission: The frame is transmitted on the outgoing interface.
This process repeats at every router until direct delivery is possible.
The traceroute (Unix) or tracert (Windows) command reveals the multi-hop path packets take. It works by sending packets with incrementing TTL values (1, 2, 3...). Each router that decrements TTL to 0 sends an ICMP Time Exceeded back, revealing its IP address. This builds a map of the path from source to destination.
Source and Destination Host Roles
While routers handle intermediate forwarding, the source and destination hosts have distinct responsibilities in host-to-host delivery.
Source Host Responsibilities:
- •Packet Construction: Creates the IP packet with complete header including source IP, destination IP, TTL, protocol field, etc.
- •Direct vs. Indirect Decision: Determines whether destination is local (direct delivery) or remote (indirect delivery).
- •Next-Hop Selection: Consults routing table to identify the gateway for indirect delivery. Most hosts have a simple routing table: local network = direct, everything else = default gateway.
- •Fragmentation (if required): If the packet is larger than the link MTU and DF flag is not set, the source may fragment it. (In IPv6, only the source can fragment.)
- •TTL Initialization: Sets an initial TTL value (commonly 64, 128, or 255) to prevent infinite routing loops.
- •Checksum Calculation: Computes the IP header checksum for error detection.
Destination Host Responsibilities:
- •Frame Filtering: At Layer 2, accepts frames addressed to its MAC, broadcast MAC, or multicast MACs it has joined.
- •IP Address Verification: Confirms the destination IP address matches one of its interfaces (or is a broadcast/multicast it should receive).
- •Checksum Verification: Validates the IP header checksum. Discards packet if checksum fails.
- •Fragment Reassembly: If packet is a fragment, buffers it and waits for remaining fragments. Reassembles when all fragments arrive (within timeout).
- •Protocol Demultiplexing: Reads the Protocol field to determine which transport layer protocol (TCP, UDP, ICMP) should receive the payload.
- •Payload Delivery: Passes the IP payload to the appropriate transport layer handler.
When the destination host sends a response, the roles reverse—the original destination becomes the source, and vice versa. Both hosts must be capable of performing both roles. This is why every Internet-connected host has a full IP stack implementation, not just the sending or receiving portions.
The End-to-End Principle
The architecture of host-to-host delivery embodies one of the most influential design principles in computer networking: the End-to-End Principle.
The Principle Stated:
"Application-level functions should be implemented at the endpoints of the communication, not within the network itself, unless doing so provides significant performance benefits that cannot be achieved otherwise."
Or, more succinctly: "Keep the network simple; push intelligence to the edges."
Implications for Host-to-Host Delivery:
| Function | Where Implemented | Why |
|---|---|---|
| Reliability (guaranteed delivery) | Endpoints (TCP) | Network cannot guarantee every path is reliable; endpoints can retransmit |
| Error detection (data integrity) | Endpoints | End-to-end checksum catches errors network might miss |
| Ordering | Endpoints (TCP) | Different packets may take different paths with varying delays |
| Congestion control | Endpoints (TCP) | Endpoints know their own traffic patterns best |
| Security (encryption) | Endpoints | Network nodes might be untrusted; only endpoints share keys |
| Routing | Network (routers) | Path selection requires global topology knowledge hosts lack |
| Fragmentation/Reassembly | Mixed (IPv4) / Endpoints (IPv6) | IPv6 moved fragmentation to endpoints for efficiency |
Why This Matters for Host-to-Host Delivery:
The end-to-end principle explains why the network layer provides best-effort delivery only:
-
Simplicity in the Core: Routers only need to forward packets based on destination addresses. They don't track connections, manage retransmissions, or ensure ordering. This allows routers to be extremely fast and handle enormous volumes of traffic.
-
Flexibility at Endpoints: Different applications have different needs. Real-time video can tolerate losses but not delays; file transfer needs perfect reliability regardless of delay. By keeping the network simple, endpoints can implement exactly the semantics they need.
-
Robustness: If routers failed mid-reliability-negotiation, complex state would be lost. By keeping state at endpoints, failures in the network core are recoverable—TCP simply retransmits.
-
Evolvability: New transport protocols (like QUIC) can be deployed on endpoints without changing network infrastructure. If reliability were in routers, upgrading would require coordinating changes across the entire Internet.
Criticisms and Modern Challenges:
The end-to-end principle is elegant but not absolute:
- NAT violates it by modifying packets mid-flight
- Firewalls add stateful inspection in the network
- CDNs move application logic into the network
- Quality of Service (QoS) requires routers to treat packets differently
These deviations reflect practical tradeoffs, but the principle remains a guiding ideal that explains the Internet's remarkable scalability.
The end-to-end principle isn't just about networks—it's a general design philosophy. When building any layered system, consider: "What's the simplest thing the inner layer can do while still being useful? Push complexity outward where it can be application-specific." This lesson from Internet architecture applies broadly.
Host-to-Host vs. Process-to-Process Delivery
A subtle but important distinction exists between what the network layer provides and what applications actually need.
Network Layer: Host-to-Host
The network layer delivers packets to a host (identified by an IP address), not to a specific application running on that host. When a packet arrives at 93.184.216.34, the network layer's job is done—the packet reached that host.
But modern computers run many applications simultaneously: a web browser, an email client, a video call, a game. How does the operating system know which application should receive an incoming packet?
Transport Layer: Process-to-Process
This is the transport layer's job. TCP and UDP add port numbers that identify specific processes:
- Source Port: Identifies the sending application
- Destination Port: Identifies the receiving application
The combination of (IP Address, Port) is called a socket and uniquely identifies an application endpoint.
- •Addressing: IP addresses
- •Identifies: Hosts/devices
- •Delivery: Source host → Destination host
- •Multiplexing: None (single logical channel per host)
- •Example: 192.168.1.10 → 93.184.216.34
- •Addressing: Port numbers (0-65535)
- •Identifies: Applications/processes
- •Delivery: Source process → Destination process
- •Multiplexing: Many applications share one IP
- •Example: 192.168.1.10:54321 → 93.184.216.34:443
Demultiplexing: From IP to Application
When a packet arrives at a host:
- Network Layer checks that the destination IP matches this host.
- Network Layer examines the Protocol field (e.g., 6 = TCP, 17 = UDP).
- Packet passed to appropriate transport protocol handler.
- Transport Layer examines the destination port number.
- Operating System delivers the payload to the application bound to that port.
This is why when you run a web server, you "bind" it to port 80 or 443—you're registering with the OS to receive traffic destined for that port.
The Complete Address Tuple:
For TCP, a connection is identified by a 5-tuple:
- Source IP
- Source Port
- Destination IP
- Destination Port
- Protocol (TCP)
This allows multiple connections from the same host to the same server (different source ports) and multiple connections to the same server port from different clients.
Ports 0-1023 are "well-known" and reserved for standard services: 80 (HTTP), 443 (HTTPS), 22 (SSH), 25 (SMTP), etc. Ports 1024-49151 are "registered" for specific applications. Ports 49152-65535 are "ephemeral" and used for client-side source ports. These ranges are conventions, not technical requirements.
KEEP LEARNING
Keep learning for free.
Read the complete lesson, save your notes and pick up where you left off with a free account. No card needed.