Network Layer in OSI Model

In this tutorial, you will learn the basic concepts of the network layer in OSI Model. After reading this tutorial, you will be able to understand why the network layer is used in computer networks, how it works on the network, and what are the responsibilities of the network layer.

Contents:

  1. Purpose of Network Layer
  2. Responsibilities of Network Layer
  3. Encapsulation and De-encapsulation
  4. IP Addressing
  5. Connectionless Services
  6. IP Packet Delivery
  7. Routing Decision
  8. Network Layer Protocols

Purpose of Network Layer

The network layer is one of the seven layers of the OSI reference model and is also known as layer-3 of the OSI model. The main purpose of the network layer is to transmit packets from one device to another. It contains the complete details of the router, which decide the optimal path to send the packets.

  • The network layer sends packets in such a way that there is less congestion on the network.
  • It uses IP, messaging, and routing protocols for communication. The IP address is used to transmit the packets, and the routing protocol is used to find the best path for the transmitting packets. Messaging protocol such as ICMP is used as reply and request protocol.
  • The network layer communicates with the transport layer and the data link layer. It receives segments from the transport layer and converts them into packets.
  • When the network layer creates the packet, it includes the sender and receiver device IP address so that the router can find the receiver and send it correctly.

The diagram below shows the network layer and the data format used in it.

Network Layer of OSI Model

As shown in the figure, the network layer is one of the layers of the OSI model, located between the transport layer and the data link layer. Also, the data format in the network layer is a packet.

advertisement
advertisement

Responsibilities of Network Layer

To provide end-to-end communication, the network layer performs basic operations such as encapsulation, forwarding, and addressing, etc. The network layer has the following responsibilities:

  1. Encapsulation and de-encapsulation: Encapsulates segments on the sender side and de-encapsulates the frames on the receiver side.
  2. IP Addressing: The IP addresses of the sender and receiver are stored in the packet header.
  3. Connectionless services: No dedicated path is established between devices in advance for communication.
  4. Routing Decision: Finds the best route to send packets.

Encapsulation and De-encapsulation

The format of data at the network layer is a packet. So, let us understand how a packet is created using encapsulation and de-encapsulation.

Encapsulation: The network layer communicates with the transport layer and receives a segment. When the network layer receives the segment, it adds the IP header to the segment that makes up the packet. This process is known as encapsulation. Packets in the network layer are also known as Network Layer Protocol Data Units (PDUs).

  • The router decides whether to send the packets based on the destination IP address store in the IP header. The IP version can be IPv4 (32-bit) or IPv6 (128-bit).
  • The IP address information will remain the same until it is delivered to the destination device. An IP address is changed if the device performs Network Address Translation (NAT), translates the original IP address into another IP address.

De-encapsulation: When a packet sent by the sender is received to the receiver, it first goes to the physical layer as a stream of bits and then to the data link layer as a frame. As the data link layer sends a frame to the network layer, the network layer removes the frame header and trailer that makes up the packet. This process is known as de-encapsulation.

The figure below explains the encapsulation and de-encapsulation process in a network layer.

encapsulation and de-encapsulation process in a network layer
  • On the receiver side, as shown in the figure, the network layer converts the segments into packets by adding an IP header and sending them to the data link layer.
  • The data link layer transmits the frame to the physical layer, and the physical layer transmits the bits to the receiver’s physical layer.
  • Whatever process is done by the sender, the reverse of those process will be done by the receiver. Therefore, when the receiver’s network layer receives a frame from the data link layer, it converts the frame into a packet, as shown in the figure.
  • On the sender and receiver side, the network layer does the encapsulation and de-encapsulation process, respectively.

IP Addressing

The network layer only understands the IP addressing scheme. It uses IP protocol for communication, and IP does not guarantee that all packets will be delivered correctly. This is known as a best-effort mechanism.

  • Internet Protocol (IP) is used at the network layer and provides the operations needed to transmit a packet from sender to receiver through multiple routers.
  • Also, IP does not track packets or manage the flow of packets. Flow control is done using layer-4 protocols like TCP.
  • IP does not depend on the type of media. It does not matter whether the media is wireless or wired. It just takes the data and sends it to the receiver.
  • IP addresses have versions IPv4 (version 4) and IPv6 (version 6). IPv4 and IPv6 are 32-bit and 128-bit in size, respectively.
  • The IP address information is stored in the IP header field of the packet.
  • Typically, IP addresses are used to make decisions on the network to find the destination for transmitted packets using a best-effort mechanism.

advertisement

Connectionless Services

In the network layer, IP uses a connectionless service which means there is no need to establish a dedicated path between the sender and the receiver before sending the data.

  • For a connectionless service, it is not necessary to establish an end-to-end connection for the exchange of IP information between the sender and the receiver.
  • Connectionless services use the same concept as sending a letter to the recipient. For example, you write a letter to your friend without informing him in advance and put it in the mailbox of the post office. Therefore, your friend will not know until your letter is received by him.

The figure below explains the connectionless service.

Connectionless Service of Network Layer

As shown in the figure, the IP header contains the IP address of the receiver. PC-1 sends the packet to PC-2, but PC-2 is not aware of it. This means that there is no pre-determined path between PC-1 and PC-2. PC-2 will inform only when it receives the packet sent by the sender.

IP Packet Delivery

IP does not have any other information in the header which is used for connection establishment. This property reduces the overhead of IP on a network.

advertisement
  • When the IP packet travels over the communication channel, it does not know whether the receiver is ready to receive the packet. Furthermore, if the receiver receives an IP packet, the sender cannot decide whether the IP packet has been successfully received by the recipient. This characteristic of IP is known as a best-effort mechanism.
  • It is necessary to use some protocols on the network to track the information of IP packets. That’s why the network layer communicates with the transport layer and uses the TCP protocol to track the information of packets sent to the receiver.

The diagram below explains the best-effort feature of the IP protocol.

Delivery of Packets using Best-Effort Mechanism
  • As shown in the figure, PC-1 sends five packets to PC-2 through the router. The router determines the path and processes the packets quickly, leading to packet loss during transmission.
  • On the receiver side, the receiver receives only four packets because one packet is lost during transmission. Furthermore, the sender does not know whether all the packets have been received correctly by the receiver.

Routing Decision

  • The decision to send packets is made in several ways. For example, a device may send packets to itself or another device that is on the same LAN or a device that is on another LAN.
  • If the two device IP addresses are in the same LAN, the sender will send the packet directly to the receiver through an intermediary device.
  • But in a real network, the packet has to be sent to the receiver, located far away from the sender. So the router works in the network layer and uses the services of the network layer to build the routing table and decide the total hops from sender to receiver.
  • A router has a gateway through which packets are transmitted from one network to another. In simple words, the router routes the traffic to another network.

Network Layer Protocols

Different types of protocols are used at the network layer for different purposes. The protocols of the network layer are as follows:

  1. Internet Protocols
  2. Routing Protocols
  3. Address Mapping Protocols
  4. Error Reporting Protocols
  • Internet Protocols (IP): Internet Protocol addresses are used to identify devices uniquely on a network. IPv4 and IPv6 are IP protocols.
  • Routing Protocols: Using routing protocols, the router uses network layer services to find the best and optimal path for sending packets from sender to receiver.
    • RIP, DVR, LSR, OSPF, EIGRP, BGP, etc., are routing protocols.
  • Address Mapping Protocols: A device knows the IP or MAC address of another device. With the help of address mapping protocol, a device can find the IP or MAC of another device if the MAC or IP address is known.
    • Finding MAC using IP is known as network mapping physical to a logical address, and finding IP using MAC is known as network mapping logical to a physical address.
    • ARP, RARP, DHCP, and BOOTP are address mapping protocols.
  • Error Reporting Protocols: If an error occurs, the IP protocol cannot notify the sender, and it does not correct the error over the network. By using error reporting protocols, a host can find out whether the router or server or destination is live or not.
    • Ping and Trace-route are debugging tools used to check the status of a device and trace the route, respectively.
    • ICMP and IGMP are error-reporting protocols.

Key Points to Remember

Here is the list of key points we need to remember about “Network Layer”.

  • The network layer (layer-3) is one of the seven layers of the OSI reference model. The main purpose of the network layer is to transmit packets from one device to another.
  • Encapsulation and de-encapsulation, IP Addressing, Connectionless services, and Routing Decision are the services and responsibilities of the network layer.
  • The network layer converts the segments into packets by adding an IP header, which is known as encapsulation. The network layer converts the frame into packets by removing the frame header and trailer, a process known as de-encapsulation.
  • The network layer understands IP addresses, so packets travel over a network through several routers to reach the receiver, depending on the receiver’s IP address.
  • In the network layer, IP uses a connectionless service which means there is no need to establish a dedicated path between the sender and the receiver before sending the data.
  • The network layer communicates with the transport layer and uses the TCP protocol to track the information of packets sent to the receiver.
  • The routing decision is made by the router, in which the router decides the best and optimal path to send the packets from sender to receiver.
  • The protocols of the network layer are as follows:
    1. Internet Protocols
    2. Routing Protocols
    3. Address Mapping Protocols
    4. Error Reporting Protocols

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.