The network layer in the OSI model is explained.

The network layer is the third layer in the OSI model. It uses the services of the data link layer and provides services to the transport layer.

The role of the network layer is to route the packet from source to destination hop by hop. The communicating entities may be directly connected or may connect via multiple intermediate sub-networks.

After receiving a packet from the transport layer, the network layer determines the outgoing link to the destination at the sender node. An intermediate node accepts packets on incoming links, does a routing table lookup, and forwards the packet to the destination.

For example, we use the Internet in our home via a WiFi connection. On one side, a WiFi router connects to the laptop over a wireless channel; on the other, it connects to the internet service provider over a WAN port.

Our laptop and WiFi router both have a network layer. When a user enters an URL address in a web browser address bar and hits the enter key, the application layer protocol HTTP ( web browser uses HTTP) sends a request to the transport layer. The transport layer sends the request message to the network layer.

The network layer sends the message to the WiFi router over the wireless medium. The network layer of the WiFi Router checks the destination IP and finds that it belongs to a web server on the Internet. The WiFi router sends the message to the ISP over the DSL line.

Till now, there is only a single outgoing link. But there can be multiple outgoing links from ISP (Internet service provider). The network layer does the routing to choose the suitable outgoing path.

What are the functions of the network layer?

Interworking of heterogeneous networks: The network layer can enable transport between several types of networks. Like our previous example, the IP layer allows interworking between the internal LAN and the public Internet.

Fragmentation and assembly of user data: Fragmentation means breaking a larger packet into smaller packets before sending it to the underlying network. Assembly is building the original packet from the received fragments at the destination. 

The network layer has to do the fragmentation to fulfill the underlying network data unit’s carrying capacity (MTU). The fragments may travel to the destination via multiple paths, but network layers wait for all segments and deliver the complete message to the transport layer after assembly.

Network Addressing: The network layer does the end-to-end logical addressing. Before sending a packet to the underlying data link layer, the network layer adds a header next to the user data. The header has source and destination logical addresses. Two addresses may be directly connected or maybe multiple hopes apart.

Network Interworking:  Interwoking means enabling communication between different types of networks to each other. The types of networks could be VLANs, Public, Private networks, and Networks with different subnet masks.

The IP layer only looks for the destination IP address for the next network hope, so that kind of IP does not matter for forwarding packets from any type of network to any other type of network.