Network Layer
The network layer (Layer 3) of OSI controls the exchange of data packets, as these cannot be directly routed to the receiver and therefore have to be provided with routing nodes. The data packets are then transferred from node to node until they reach their target. To implement this, the network layer identifies the individual network nodes, sets up and clears connection channels, and takes care of routing and data flow control. When sending the packets, addresses are evaluated, and the data is routed through the network from node to node. There is usually no processing of the data in the layers above the L3 in the nodes. Based on the addresses, the routing and the construction of routing tables are done.
In short, it is responsible for the following functions:
- Logical Addressing
- Routing
Protocols are defined in each layer of OSI, and these protocols represent a collection of rules for communication in the respective layer. They are transparent to the protocols of the layers above or below. Some protocols fulfill tasks of several layers and extend over two or more layers. The most used protocols on this layer are:
- IPv4 / IPv6
- IPsec
- ICMP
- IGMP
- RIP
- OSPF
It ensures the routing of packets from source to destination within or outside a subnet. These two subnets may have different addressing schemes or incompatible addressing types. In both cases, the data transmission in each case goes through the entire communication network and includes routing between the network nodes. Since direct communication between the sender and the receiver is not always possible due to the different subnets, packets must be forwarded from nodes (routers) that are on the way. Forwarded packets do not reach the higher layers but are assigned a new intermediate destination and sent to the next node.
IP Addresses
Each host in the network located can be identified by the so-called Media Access Control address (MAC). This would allow data exchange within this one network. If the remote host is located in another network, knowledge of the MAC address is not enough to establish a connection. Addressing on the Internet is done via the IPv4 and/or IPv6 address, which is made up of the network address and the host address.
It does not matter whether it is a smaller network, such as a home computer network, or the entire Internet. The IP address ensures the delivery of data to the correct receiver. We can imagine the representation of MAC and IPv4 / IPv6 addresses as follows:
- IPv4 / IPv6 - describes the unique postal address and district of the receiver's building.
- MAC - describes the exact floor and apartment of the receiver.
It is possible for a single IP address to address multiple receivers (broadcasting) or for a device to respond to multiple IP addresses. However, it must be ensured that each IP address is assigned only once within the network.
IPv4 Structure
The most common method of assigning IP addresses is IPv4, which consists of a 32-bit binary number combined into 4 bytes consisting of 8-bit groups (octets) ranging from 0-255. These are converted into more easily readable decimal numbers, separated by dots and represented as dotted-decimal notation.
Thus an IPv4 address can look like this:
Each network interface (network cards, network printers, or routers) is assigned a unique IP address.
The IPv4 format allows 4,294,967,296 unique addresses. The IP address is divided into a host part and a network part. The router assigns the host part of the IP address at home or by an administrator. The respective network administrator assigns the network part. On the Internet, this is IANA, which allocates and manages the unique IPs.
In the past, further classification took place here. The IP network blocks were divided into classes A - E. The different classes differed in the host and network shares' respective lengths.
Subnet Mask
A further separation of these classes into small networks is done with the help of subnetting. This separation is done using the netmasks, which is as long as an IPv4 address. As with classes, it describes which bit positions within the IP address act as network part or host part.
Network and Gateway Addresses
The two additional IPs added in the IPs column are reserved for the so-called network address and the broadcast address. Another important role plays the default gateway, which is the name for the IPv4 address of the router that couples networks and systems with different protocols and manages addresses and transmission methods. It is common for the default gateway to be assigned the first or last assignable IPv4 address in a subnet. This is not a technical requirement, but has become a de-facto standard in network environments of all sizes.
Broadcast Address
The broadcast IP address's task is to connect all devices in a network with each other. Broadcast in a network is a message that is transmitted to all participants of a network and does not require any response. In this way, a host sends a data packet to all other participants of the network simultaneously and, in doing so, communicates its IP address, which the receivers can use to contact it. This is the last IPv4 address that is used for the broadcast.
Binary system
The binary system is a number system that uses only two different states that are represented into two numbers (0 and 1) opposite to the decimal-system (0 to 9).
An IPv4 address is divided into 4 octets, as we have already seen. Each octet consists of 8 bits. Each position of a bit in an octet has a specific decimal value. Let's take the following IPv4 address as an example:
- IPv4 Address: 192.168.10.39
Here is an example of how the first octet looks like:
1st Octet - Value: 192
IP Addresses
Values: 128 64 32 16 8 4 2 1
Binary: 1 1 0 0 0 0 0 0
If we calculate the sum of all these values for each octet where the bit is set to 1, we get the sum:
The entire representation from binary to decimal would look like this:
IPv4 - Binary Notation
IP Addresses
Octet: 1st 2nd 3rd 4th
Binary: 1100 0000 . 1010 1000 . 0000 1010 . 0010 0111
Decimal: 192 . 168 . 10 . 39
- IPv4 Address: 192.168.10.39
This addition takes place for each octet, which results in a decimal representation of the IPv4 address. The subnet mask is calculated in the same way.
IPv4 - Decimal to Binary
IP Addresses
Values: 128 64 32 16 8 4 2 1
Binary: 1 1 1 1 1 1 1 1
Subnet Mask
IP Addresses
Octet: 1st 2nd 3rd 4th
Binary: 1111 1111 . 1111 1111 . 1111 1111 . 0000 0000
Decimal: 255 . 255 . 255 . 0
- IPv4 Address: 192.168.10.39
- Subnet mask: 255.255.255.0
CIDR
Classless Inter-Domain Routing (CIDR) is a method of representation and replaces the fixed assignment between IPv4 address and network classes (A, B, C, D, E). The division is based on the subnet mask or the so-called CIDR suffix, which allows the bitwise division of the IPv4 address space and thus into subnets of any size. The CIDR suffix indicates how many bits from the beginning of the IPv4 address belong to the network. It is a notation that represents the subnet mask by specifying the number of 1-bits in the subnet mask.
Let us stick to the following IPv4 address and subnet mask as an example:
- IPv4 Address: 192.168.10.39
- Subnet mask: 255.255.255.0
Now the whole representation of the IPv4 address and the subnet mask would look like this:
- CIDR: 192.168.10.39/24
The CIDR suffix is, therefore, the sum of all ones in the subnet mask.
IP Addresses
Octet: 1st 2nd 3rd 4th
Binary: 1111 1111 . 1111 1111 . 1111 1111 . 0000 0000 (/24)
Decimal: 255 . 255 . 255 . 0
Subnetting
The division of an address range of IPv4 addresses into several smaller address ranges is called subnetting.
A subnet is a logical segment of a network that uses IP addresses with the same network address. We can think of a subnet as a labeled entrance on a large building corridor. For example, this could be a glass door that separates various departments of a company building. With the help of subnetting, we can create a specific subnet by ourselves or find out the following outline of the respective network:
- Network address
- Broadcast address
- First host
- Last host
- Number of hosts
Let us take the following IPv4 address and subnet mask as an example:
- IPv4 Address: 192.168.12.160
- Subnet Mask: 255.255.255.192
- CIDR: 192.168.12.160/26
We already know that an IP address is divided into the network part and the host part.
Network Part
In subnetting, we use the subnet mask as a template for the IPv4 address. From the 1-bits in the subnet mask, we know which bits in the IPv4 address cannot be changed. These are fixed and therefore determine the "main network" in which the subnet is located.
Host Part
The bits in the host part can be changed to the first and last address. The first address is the network address, and the last address is the broadcast address for the respective subnet.