Want to keep learning?

This content is taken from the Raspberry Pi Foundation & National Centre for Computing Education's online course, Networking with Python: Socket Programming for Communication. Join the course to learn more.

The layered networking model

Throughout this course you will see that networking is full of abstractions. In many cases, the complex details of the protocols and communication systems involved can be overlooked in favour of a higher-level view. This is most commonly seen in the layered network models that describe the operation of networks, including the internet. In this step I will explore one of these models with you to build your foundation for the rest of the course.

OSI or TCP/IP

There are two layered models that are often applied to networking: the seven-layer OSI model and the four-layer TCP/IP model. The TCP/IP layers envelop the OSI ones, so I will focus on the TCP/IP model for this course. If you want to, you can learn more about the OSI model here.

The layers of TCP/IP

Four boxes representing the four layers of the TCP/IP model, labelled from top to bottom as "Application", "Transport", "Network" and "Data Link". The "Application" box contains the protocols "HTTP", "FTTP","Telnet","NTP","DHCP" and "PING". The "Transport" box contains the protocols "TCP" and "UDP". The "Network" box contains the protocols "IP", "ARP", "ICMP" and "IGMP". The "Data Link" box contains the protocols "WiFi" and "Ethernet".

When looking at this model, it is conventional to work from the top down. This is because there is actually a secret fifth layer — the user — that each of the others is designed to serve.

The application layer

The highest level of the model, the application layer, is the closest to the user. Networked applications such as web browsers, email clients, and online video games all operate at this level.

The application layer encompasses the systems that prepare data for the applications too, such as encryption/decryption systems and the decoders that take raw binary data and translate it into the appropriate format for your application (HTML for your browser, or text and images for your email). Data in this layer is transmitted using an application protocol such as HTTP (Hypertext Transfer Protocol) or FTP (File Transfer Protocol) that can be understood by the application receiving the data.

The transport layer

The second layer deals with the transport of the data, and its accompanying application protocol. This layer will wrap the data in a way specified by a transport protocol.

The transport protocol ensures that both the start and end point of communication know what to expect and how to unpack any message that is sent. The benefit of separating this layer from the application layer is that many different types of application and operating system can communicate with one another, and use the internet to do so.

The transport protocols I will focus on during this course are the Transmission Control Protocol (TCP, hence the name of the TCP/IP model) and the User Datagram Protocol (UDP).

A computer may have multiple networked applications running on it simultaneously; to direct data to the correct application, the computer will assign a port to each networked connection. Ports take the form of a number from 1 to 65535, and every application that has an open network connection will have one.

The network layer

This layer is dominated by the Internet Protocol (IP) addressing system. Almost all internet-connected applications use it to route their data to its destination across the many networks that comprise the internet.

There are two types of IP address. Internet Protocol version 4 (IPv4) addresses are 32-bit numbers usually written as four numbers in the range 0–255 (that is, 8-bit numbers) separated by dots, for example 127.5.64.87. In 1998, these IP addresses were starting to run out, so Internet Protocol version 6 was created, which uses 128-bit number addresses usually written as 8 hexadecimal numbers, for example 2001:db8:0:0:0:ff00:42:8329.

The final layer of the model deals with individual connections between machines. The protocols used here can vary, both in the type of connection (wired or not) and the type of network (local or wide area networks).

This also includes the initial connection between a user’s machine and the internet, whether by UTP cable (commonly referred to as an Ethernet cable) or a wireless connection such as WiFi.

How do the layers apply to you?

As you follow along, I’ll show you how to navigate the application and transport layers with your programs. The bottom two levels (the network and data link layers) will differ for everyone, but we can mostly abstract away these details.

Before continuing, research the answers to the following:

  1. What is your device’s IP address?

    Try typing “What is my IP address?” into google. (DO NOT post it in the comments; keep it to yourself. You will need to know it for the rest of the course.)

  2. What kind of network are you connected to?

    Every network will have restrictions, especially those at work or at school. Check out your network to make sure you can communicate internally and externally.

Post a comment if you have any trouble looking up this information, or if you can help someone else out. Our course facilitation team are on hand to offer advice and support, too.

Share this article:

This article is from the free online course:

Networking with Python: Socket Programming for Communication

Raspberry Pi Foundation