On the IP Protocol

Last updated on

Overview & Background

Protocols are how communications are established over networks. The ISO/OSI model was set by ISO as theoretical background to map out a specific structure for the different layers of a network stack. Although it is rarely implemented, the ISO/OSI model is still widely used in academic backgrounds as well as a basis when discussing networks. It is used as a reference for the implementations of the actual protocols in use.

Every layer has its own data structure that it passes on to the next layer. Those structures are referred to as packets and are made of a header and a payload. The header contains fields specific to the protocol and the layer, whereas the payload is the content or information carried by the packet.

The packet of a layer is the payload of the one below it, meaning that each layer adds its own header before passing the packet to the layer under it. This is called encapsulation.

TCP/IP

Internet relies on TCP/IP (also referred to as the Internet Protocol suite), which is an implementation of the OSI model in 4 layers: application, transport, network and data link (note: the OSI model is made of 7 layers, some of which are merged in TCP/IP depending on their functionality. Refer to the previous link on OSI model for further information).

Application Layer

This is where user applications perform their tasks and where the packets originate as output from users' interaction.
Examples of protocols that operate on the application layer are FTP, SSH, HTTP, SMTP…

Transport Layer

This layer ensures that the communication is established between two hosts on a network.
Examples of protocols that operate on the transport layer are TCP and UDP.

Network Layer

Also known as the Internet layer, this is where routing takes place so that packets can be from source to destination possibly across different networks.
Examples of protocols that operate on the network layer are IP, ICMP, IGMP…

The data link layer, as its name indicates, ensures that two devices on the same link (network) can communicate through local hardware interfaces. The layer manages different devices such as network cards or layer 2 switches (there are other types of switches that are not designed to operate on this layer) that enable the packets to be transmitted over a physical transmission medium. The packets on this layer are referred to as frames.
Examples of protocols that operate on the data link layer are ARP and Ethernet.

The Mighty Internet Protocol

As mentioned in the previous section, IP operates on the network layer. It is in charge of delivering the datagrams of the hosts involved and uses IP addressing for that. It also enables routing, which is one of the most important functions of the network layer.

Adressing

As you might already know, IP addresses come in two flavors: IPv4 and IPv6.

IPv4 is an address where every octet (byte) holds a decimal value from 0 to 255 (2⁸). Addresses can thus range from 0.0.0.0 to 255.255.255.255. Some of the addresses are reserved for special purposes and should not be assigned to regular hosts.

To fully identify a host, we also need to identify the network it is part of. To do that we use what is called a netmask or subnet mask. A netmask gives the portion of the address which belongs to the network as well as the host portion. To make it more clear, let’s look at an example:
If we take 192.168.5.100 as an address, and a netmask of 255.255.254.0, we can find the part that identifies the network by performing a bitwise & operation on both addresses. The result is 192.168.5.0, and this is called a network prefix.

Note: the inverse of the netmask allows you to determine how many hosts a network can contain. In our previous example, with a netmask of 255.255.254.0 of which the inverse is 0.0.1.255, we have 9 bits that can be used to represent hosts, meaning 2⁹ possible addresses.

IPv6 came as an extension due to the limited number of addresses that can be assigned imposed by the structure of IPv4 addresses. IPv6 addresses are in hexadecimal, and consist of 8 groups (16 bits each) separated by colons. Example: 2001:db8:1111:a:b0:0:9000:200. Refer to the following link for additional details.

Routing

Thanks to the IP protocol, routers are able to move (route) packets through networks using routing protocols and addressing. Routers make use of what is called a routing table (which you can display using ip route if you are on Linux) to determine the best path a packet should take. Routing tables store the available interfaces as well as the networks they are connected to, and metrics that are assigned to each of the available links of a network (congestion and bandwidth are examples of those). Based on those metrics, the routing protocol used by the router can choose where to forward the packet. Examples of routing protocols are OSPF and BGP.