Skip to main content

Network Layer

Network Layer

Network Layer

The Network Layer is the third layer in the OSI model. It is responsible for host-to-host communication, ensuring that data packets are routed across networks to reach their final destination.

Host-to-Host Delivery​

Host-to-host communication refers to the transfer of data from the source host (device) to the destination host. These devices can be in the same network or different networks.

Example: Imagine you're sitting at home and sending a message to your friend who lives in another country. Your network might be a Local Area Network (LAN), and your friend's network could be his own LAN. The message travels from your device in your LAN to your friend's device in his LAN, crossing various intermediate networks.

In the Transport Layer, we discussed end-to-end delivery, focusing on communication between applications. In contrast, host-to-host delivery at the Network Layer involves the transfer of data until it reaches the final computer or device.

Packetization​

The Network Layer takes the data segments received from the Transport Layer and attaches an IPv4 or IPv6 header to each segment. The resulting combination is called a packet. This header contains essential information such as the source and destination IP addresses, which are crucial for routing.

Fragmentation​

The maximum transmission unit (MTU) at the Network Layer is typically 64KB. However, the MTU at the Data Link Layer, which is below the Network Layer, is often much smaller, usually just a few bytes. To accommodate this, the Network Layer may need to fragment packets into smaller pieces to ensure they can be transmitted over the network. These smaller packets are reassembled at the destination.

Logical Addressing​

Logical addressing, also known as IP addressing, involves assigning a unique IP address to each device on a network. This unique address allows devices to locate and communicate with each other over a network, enabling host-to-host delivery.

Example: When you type www.google.com into your web browser, the DNS translates this domain name into an IP address (e.g., 142.250.72.206). Your computer, with its IP address (e.g., 192.168.1.2), uses this IP address to send a request to the Google web server. The server responds with the requested web page, sending data back to your computer's IP address.

Routing​

Routing is the process of determining the best path that data packets should take to reach their destination. Routers use routing tables and protocols to find the most efficient path for packet forwarding.

Routing protocols such as Routing Information Protocol (RIP), Open Shortest Path First (OSPF), and Border Gateway Protocol (BGP) are essential for managing how data travels across networks.

Routing Table​

Routers use routing tables to decide where to forward packets. A typical routing table includes:

  • Destination IP: The IP address of the destination network or host.

  • Next Hop IP: The IP address of the next router or device along the path to the destination.

  • Metric/Cost: A value representing the "cost" of reaching the destination, based on factors like hop count, bandwidth, or delay. This helps in selecting the best path.

Inter-Domain Routing​

Inter-domain routing is used when data needs to travel between different organizations or autonomous systems.

Example: Suppose Apple and OpenAI are two separate organizations with their own internal networks. They need to communicate for data exchange, such as integrating ChatGPT into Apple's virtual assistant. Inter-domain routing allows efficient and reliable data exchange between these networks.

Packet Forwarding​

Once a router determines the best path for a packet using its routing table, it forwards the packet to the next hop (another router or the destination device). Packet forwarding is a collaborative task between the Network Layer (for routing decisions) and the Data Link Layer (for actual frame forwarding).

  • Network Layer: Determines the IP address of the next hop device based on the routing table.

  • Data Link Layer: Forwards the packet to the appropriate device within the same network using MAC addresses.

To forward the packet to a device within the same network, the router needs the device's MAC address. The Address Resolution Protocol (ARP) is used to map IP addresses to MAC addresses. Once the mapping is done, the Data Link Layer handles the actual transmission of frames based on MAC addresses within the local network segment.