The main functions of the network layer are defining logical addresses, finding paths based on logical addresses to reach the destination, and connecting different media types such as Ethernet, Fiber optical, Serial, and Token Ring.
Logical addressing
The network layer provides logical addressing for the network. These addresses are used to group networking components together and find a specific component from all components. These addresses are known as IP addresses. IP addresses have two components: a network and a host component.
A network component is a group ID. All group members use the same network component in their addresses. A host component is an individual ID. All group members use different host components in their addresses. In IP addresses, both components are written together. To identify a network and host component in an IP address, one more address is used with the IP address. This address is known as the subnet mask. A subnet mask separates a network component from the host component in the IP address.
IP addresses use numbers for network and host components. IP addresses' numbers are 32 bits in length. To make these numbers more readable, they are broken up into 4 bytes, or octets, where any 2 bytes are separated by a period. Some example IP addresses are 1.1.1.1, 2.2.2.2, 10.0.0.1, 192.168.1.1, and 172.168.0.1. Writing numbers in this way is known as dotted decimal notation.
An IP address is always written with the subnet mask. A subnet mask is also 32 bits in length. There are two ways to write a subnet mask with the IP address: dotted decimal notation and slash notation.
In dotted decimal notation, a subnet mask is exactly written as an IP address. 2550.0.0.0, 255.255.0.0, and 255.255.255.0 are some example subnet masks in dotted decimal notation.
In slash notation, the number of network bits in the IP address is written after a slash. Some examples of subnet masks in the slash notation are /24, 16, and /8.
Routing
If two devices have different network IDs, they can not communicate directly. To move information between devices that have different network IDs, a router is used. A router connects different networks. It switches data packets between different networks in a process called routing.
When a device sends a data packet to another device, it attaches the IP address of that device to the data packet and gives it to the default gateway router. A default gateway router connects the network segment to the network. When it receives a data packet from the segment, it reads the destination IP address written on the data packet, takes the routing decision based on its routing table, and forwards the packet to the destination network.
Routers save route information in routing tables. When it receives a data packet, it compares the data packet's destination address with the routing table to find the route information. If it finds a route for the destination address, it uses that route to forward the packet to the destination. If it does not find a route in the routing table, it discards the packet. This process is called a routing decision. Routers take routing decisions for all packets it receives.
Connecting different media types
The physical layer transports data. To move data between two devices, it uses many media types such as Ethernet, FDDI, fiber-optical, radio signals, etc. Every media type uses different encapsulation techniques and methods.

A data packet encapsulated by a media type cannot be de-encapsulated by another media type. Routers can encapsulate and de-encapsulate data packets for all media types. If a source and destination are connected through different media types or belong to different network architectures, a router is used to connect them.