The network layer acts as the backbone of end-to-end communication across the global Internet, abstracting the underlying physical transmission media into a cohesive, logical routing structure. By managing logical addressing, packet switching, error reporting, and hardware translation, this layer ensures that data packets are successfully routed from source to destination across diverse physical networks.
At the architectural level, transport paths across intermediate nodes must rely on switching mechanisms to route data. Computer networks historically evolved from circuit-switched systems to modern packet-switched systems.
+-------------------------------------------+
| Switching Methods |
+--------------------+----------------------+
|
+-------------------+-------------------+
| |
+----------v----------+ +----------v----------+
| Circuit Switching | | Packet Switching |
+---------------------+ +----------+----------+
|
+---------------+---------------+
| |
+----------v----------+ +----------v----------+
| Connectionless | | Connection-Oriented |
| (Datagram Network) | | (Virtual Circuit) |
+---------------------+ +---------------------+In circuit switching, a dedicated physical or logical path is established between the source and destination before transmission begins.
In packet switching, messages are segmented into smaller, self-contained units called packets (or datagrams at the IP layer). These packets are individually routed through the network.
Modern packet-switched network layers are implemented as either connectionless or connection-oriented services.
In a connectionless packet-switched network, each packet is treated as an independent entity called a datagram.
Packet [SA|DA|Data] ---> [ Router ] ---> Output Interface 2 (Based on DA)In a connection-oriented packet-switched network, a logical path called a virtual circuit (VC) is established between the source and destination before any data packets are sent.
Router Virtual Circuit Table:
+---------------+---------------+----------------+---------------+
| Incoming Port | Incoming Label| Outgoing Port | Outgoing Label|
+---------------+---------------+----------------+---------------+
| 1 | L1 | 2 | L2 |
+---------------+---------------+----------------+---------------+In a connectionless network, the delay is dominated by packet processing and transmission times at each hop, but there is zero setup delay:
In connection-oriented virtual circuits, a setup time () and teardown time () are introduced, but intermediate forwarding delays () are minimized due to simple label-switching lookups:
An IP address is a 32-bit identifier that uniquely and universally defines the connection of a host or router interface to the global Internet.
The total address space of IPv4 is:
To make the binary addresses readable, three notations are used:
129.11.11.239). Each decimal represents bits ( byte), ranging from to .10000001 00001011 00001011 11101111).0x (e.g., 0x810B0BEF).Binary: 10000001 . 00001011 . 00001011 . 11101111
| | | |
Decimal: 129 . 11 . 11 . 239
| | | |
Hex: 81 . 0B . 0B . EF ---> 0x810B0BEFManipulating IPv4 addresses and masks requires three primary bitwise operations:
To calculate the total number of addresses in a block spanning from a starting address () to an ending address (), we interpret the addresses as base-256 integers:
Historically, IP addresses were structured using classful boundaries. Due to inefficient address allocation, this was replaced by classless addressing.
In classful addressing, the 32-bit space was divided into five distinct classes: A, B, C, D, and E. The class of an address can be identified by analyzing its leading bits:
Class A: 0------------------------------------ (0.0.0.0 to 127.255.255.255)
Class B: 10----------------------------------- (128.0.0.0 to 191.255.255.255)
Class C: 110---------------------------------- (192.0.0.0 to 223.255.255.255)
Class D: 1110--------------------------------- (224.0.0.0 to 239.255.255.255) - Multicast
Class E: 1111--------------------------------- (240.0.0.0 to 255.255.255.255) - ReservedClassful addresses are divided into a network identifier (netid) and a host identifier (hostid):
255.0.0.0. Accommodates up to hosts per block.255.255.0.0. Accommodates hosts per block.To avoid wasting internal addresses, organizations divided their allocated blocks into multiple smaller, physical subnetworks. This introduces a three-level hierarchy (Netid Subnetid Hostid). The default class mask is modified by borrowing bits from the hostid field to create the subnet mask.
Classless Inter-Domain Routing (CIDR) replaced classful boundaries with variable-length blocks. In classless addressing, a block of addresses is defined by an IP address and a prefix length ().
CIDR uses slash notation: IP_Address/n, where is the prefix length (e.g., 192.168.1.0/24).
For a given CIDR address block defined as :
Number of Addresses ():
First Address (Network Address): Set the rightmost bits of the address to .
Consider the address 110.23.120.14/20.
Prefix length: .
Suffix length: .
Subnet Mask: The first bits are , and the remaining bits are : .
As the availability of public IPv4 addresses declined, Network Address Translation (NAT) was introduced as a transition technology. It allows a private network to use a single public IP address (or a small pool of addresses) for external Internet communication.
Private Network (Inside) Public Network (Outside)
+----------------------+ +----------------------+
| Host A: 192.168.1.10 | ---\ | |
+----------------------+ | | |
+--> [NAT Router] ---> Global Server: |
+----------------------+ | (Public IP: | 8.8.8.8 |
| Host B: 192.168.1.20 | ---/ 203.0.113.5) | |
+----------------------+ +----------------------+The Internet Assigned Numbers Authority (IANA) reserved three blocks of IPv4 address space for private networks:
10.0.0.0 to 10.255.255.255 (10.0.0.0/8)172.16.0.0 to 172.31.255.255 (172.16.0.0/12)192.168.0.0 to 192.168.255.255 (192.168.0.0/16)In an IP-only NAT translation scheme, the translation table maps one private IP directly to one public IP.
To bypass the limitations of IP-only mapping, modern NAT routers use Network Address Port Translation (NAPT). NAPT maps transport layer identifiers (port numbers) alongside IP addresses, allowing thousands of private sessions to share a single public IP address simultaneously.
NAPT Translation Table Example
+-----------------------+-------------+----------------------+-------------+
| Private Source IP | Private Port| Public Source IP | Public Port |
+-----------------------+-------------+----------------------+-------------+
| 192.168.1.10 | 1024 | 203.0.113.5 | 40001 |
| 192.168.1.20 | 1024 | 203.0.113.5 | 40002 |
+-----------------------+-------------+----------------------+-------------+When an outgoing packet is intercepted:
Every device on a physical network is identified by a logical (IP) address and a physical (MAC) address. When a host needs to transmit an IP datagram, it must encapsulate it in a Layer 2 frame, which requires knowing the destination's physical address. The Address Resolution Protocol (ARP) dynamically maps a 32-bit logical IP address to a 48-bit physical MAC address.
+-------------------------------------------------------+
| ARP Packet |
+---------------------------+---------------------------+
| Hardware Type (16 bits) | Protocol Type (16 bits) |
+---------------------------+---------------------------+
| Hardware Size (8 bits) | Protocol Size (8 bits) |
+---------------------------+---------------------------+
| Opcode (16 bits) |
+-------------------------------------------------------+
| Sender Hardware Address (MAC) |
+-------------------------------------------------------+
| Sender Protocol Address (IP) |
+-------------------------------------------------------+
| Target Hardware Address (MAC) |
+-------------------------------------------------------+
| Target Protocol Address (IP) |
+-------------------------------------------------------+ Host A (192.168.1.1) Host B (192.168.1.2)
| |
| ------ [ARP Request (Broadcast: Who is 1.2?)] ---->|
| | (Saves A's MAC)
|<------- [ARP Reply (Unicast: I am 1.2, MAC_B)] ----|FF:FF:FF:FF:FF:FF. Every host on the local segment processes this frame.0x0806.ARP is used in four distinct networking scenarios:
Proxy ARP is a technique where a router answers ARP requests on behalf of another device. This is often used to join two physical networks separated by a router without using subnetting, or to enable remote access VPN connections.
Because the IP protocol is connectionless and best-effort, it lacks built-in mechanism for reporting transmission errors. The Internet Control Message Protocol (ICMP) serves as the diagnostic and control companion to IP.
+-----------------------+
| IP Header | (Protocol field = 1)
+-----------------------+
| ICMP Header | (Type, Code, Checksum)
+-----------------------+
| ICMP Data | (Diagnostic payload)
+-----------------------+ICMP messages are encapsulated directly inside IP datagrams.
ICMP messages are categorized into Error-Reporting Messages and Query Messages.
ping utility.Like IP, ICMP uses a 16-bit checksum to detect corruption in its header and data payload.
0x0000./n) to reduce address waste.ping).The distinction between connectionless datagram networks (forwarding based on destination address) and connection-oriented virtual-circuit networks (forwarding based on path labels).
A flexible IP allocation mechanism replacing classful addressing, utilizing variable-length subnet masks denoted by prefix lengths (slash notation).
A technology that maps private local IP addresses to a limited pool of globally unique public IP addresses, utilizing port mapping (NAPT) to multiplex sessions.
The dynamic mapping protocol that translates 32-bit logical IP addresses into 48-bit physical MAC addresses within a local area network.
A companion protocol at the network layer used by hosts and routers to report transmission errors and execute diagnostic queries.
Test your understanding with 5 questions
In a connectionless packet-switched network, what parameter does a router use to make its packet forwarding decisions?
An organization is assigned the IPv4 address block 110.23.120.14/20. What is the first address (network address) in this block?
Which of the following statements is true regarding flow control in the network layer of today's TCP/IP Internet?
Which ICMP destination-unreachable message codes can be generated only by the destination host rather than intermediate routers?
How does NAPT (Network Address Port Translation) allow multiple internal private hosts to share a single public IP address simultaneously to access the same external server?
255.255.255.0. Accommodates hosts per block.Last Address (Broadcast Address): Set the rightmost bits of the address to .
11111111.11111111.11110000.00000000255.255.240.0First Address Computation:
We evaluate the third byte: 120 in binary is 01111000. The third byte of the mask is 240 (11110000 binary).
Hence, the first address is 110.23.112.0/20.
Number of Addresses ():
Last Address Computation:
Invert the mask 255.255.240.0 to get wildcards: 0.0.15.255. Apply bitwise OR:
Hence, the last address is 110.23.127.255/20.
6 Modules
6 Modules