An introduction to networking
A computer network (also referred to as a "data network", or simply a "network") consists to a set of devices connected together in order to be able to exchange data between themselves. These devices create a network using their respective network interfaces. Some devices may use a single network interface, other devices may be connected to the network via multiple interfaces.
The type of interface(s) used by a device to connect to a network depends on the medium being used to connect. A wireless network interface is used to connect to a network over-the-air using a standard such as IEEE 802.11. There are various types of wired mediums in use today, the most common of which follows the IEEE 802.3 standard (Ethernet). Most devices that have a wired network interface will have at least one Ethernet interface.
Types of devices in a network (based on their function)
A device that exists on a computer network may be referred to as a node. Based on the function of a node within the network, we can classify it as one of 2 types of devices:
- hosts - these are devices that either store data that may be requested by other hosts, or devices that request data from other hosts in order to perform a certain function. For example a laptop, or a web server.
- network devices - these are devices that facilitate the transfer of data between other devices. For example a network switch or a router.
Host devices themselves can be further classified based on their primary function:
- clients: these are devices that primarily request data from other hosts in order to perform a certain function. For example a laptop or a desktop.
- servers: these are devices that primarily store or process data in order to send them to a client device when requested. For example, a web server or an email server.
- peripherals: these are devices that perform a specific function in a network. For example, a printer.
- peer-to-peer devices: these devices act both as a client and a server to other hosts on the network. A device may be a client device for some applications (like a web browser) and a peer-to-peer device for other applications (such as BitTorrent) at the same time.
The mechanics of data transfer in a computer network
As we have stated earlier, the primary purpose of creating a computer network is to allow devices to exchange data between themselves. How exactly does this data exchange happen? Let's take a look at the mechanics of data transfer in a computer network.
Network Headers, Layers and Encapsulation
When one device needs to send data to another device over a computer network, the data is "encapsulated" in several layers of "headers". At each layer, the information carried in the header represents some important piece of information about the source of the data being transported, and its intended destination. The Layers themselves are described by a theoretical model known as the Open Systems Interconnection (OSI) Model.
Let's use an example to describe how this would work.
Consider the following scenario. There are 5 computers and a server connected together via a switch for form a network. The server (Device F) has a web-server application running on it. Suppose the user on Device A (a computer) opens a new tab in a browser window and requests a web page that is stored on web server F. In order for this request to make its way to Device F and be processed by the correct application (or process) running on Device F, the request from Device A must include a number of items of information along with the request that it sends.
The request to download the home page of the web server application running on Device F would follow a format specified in the HTTP protocol and look like the following:
There may be many applications (or processes) running on a server. When this request arrives at Device F, there must be some method to identify the application (or process) that the request is intended for. In order to identify the application on Device F that must handle this request, the request must be encapsulated in a Transport Layer (Layer 4) header.
The 2 most common Transport Layer protocols are Transmission Control Protocol (TCP) and User Datagram Protocol (UDP). The HTTP protocol (and as a consequence web servers and client browser applications) user TCP as the transport layer protocol to transfer traffic. In order for the HTTP request from Device A to be directed to the correct application running on Device F, the request must be encapsulated in a TCP header.
Transport Layer protocol (both TCP and UDP) headers include a field known as the Destination Port. The destination port in a TCP or UDP header is not a physical port or interface on a device. It is simply a field in the header, and is a number between 0 and 65535. A web server application, by default, listens for incoming requests on a "well-known" TCP port number 80 (or 443 for secure HTTP).
The HTTP request above must therefore be encapsulated in a TCP Header where the Destination port is set to 80. The request now looks like this:
So far we have created an HTTP request, and we have identified the application that must process the request on the receiving device. We now need to uniquely identify the receiving device itself, out of all the devices that exist on the network. We do this by encapsulating the entire request (which currently consists of HTTP request encapsulated in a TCP Header) in a network layer (Layer 3) header. The most common network layer protocol in use today is Internet Protocol (IP). (IP version 4 to be exact.)
This request now needs to encapsulated in an IP header. One of the fields in an IP Header is the Destination IP Address. The destination IP Address in the IP header must be set to the IP Address assigned to Device F (10.0.0.10 - as seen in the diagram above). The request now looks like this:
We now have a request that is encapsulated in a TCP (Transport Layer) header, and an IP (Network Layer) header. The Destination IP Address in the IP Header identifies the intended recipient via its Network Layer Address. However, this is not yet sufficient to ensure that the request arrives at the correct destination device.
The devices in this example are connected via their respective Ethernet interfaces to an Ethernet switch. Ethernet is a Data Link Layer (Layer 2) protocol. In order for the HTTP request to make it to Device F, we now need to add a Data Link (or Layer 2) header. In this case, it would be an Ethernet Header.
The Ethernet Header contains a field for the Destination MAC Address. This would be the MAC Address of the Ethernet interface on Device F. The MAC Address is a hardware address. Every Ethernet interface is assigned a unique MAC Address by the manufacturer of the interface. The Destination MAC Address in the Ethernet Header is set to the MAC Address of the Ethernet interface on Device F (we will suppose this to be the address EC:70:2C:5D:AF:F2).
We now have an HTTP Request encapsulated in Layer 4, Layer 3 and Layer 2 headers. The Layer 4 (TCP) header identifies which application on the destination device should handle the request. The Layer 3 (IP) header identifies which device the request is being sent to. The Layer 2 header identifies the physical Ethernet MAC address of the interface of the device that the request is being sent to.
When this request arrives at Device F, it will be forwarded to the application that is "" on TCP port 80. The web server application (which is listening on TCP port 80) processes the request and creates a response to be sent back to the originator of the request.
How does Device F (and the web server application running on it) know who to send the response back to? In order to send the response back to the correct device on the network, Device F will inspect other fields in the headers encapsulating the HTTP request.
In order to allow for full two-way communication in a network, there exists a corresponding "Source" field for every "Destination" field in the Transport, Network and Data-link layer headers. The Ethernet header will include the MAC Address of Device A's Ethernet interface (we will assume this to be 70:F4.7D:A5.BC:4F):
The IP header will include Device A's IP Address in the "Source Address" field (10.0.0.91 - as seen in the diagram above):
The TCP header will also include a "Source Port" field. When a tab in a browser window makes an HTTP request, the Operating System dynamically generates a TCP Source Port and assigns it to the specific tab in the browser window. Each tab in each browser window in a computer will be assigned a different (unique) TCP Source Port. Generally, the TCP source port assigned to browser tabs is a high number (10000 and greater). In our case let's assume that the OS assigns port number 10801 to this particular browser tab. This will be indicated as the Soure Port in the TCP header.
The HTTP request encapsulated in headers with all of the Source and Destination fields completed will look like this:
Data Link (MAC)Layer 2
Network (IP)Layer 3
Transport (TCP)Layer 4
When this request arrives at Device F, it is forwarded to the web server application that is listening on TCP port 80. The web server creates a response that would look something like this (the ... represents the actual HTML markup generated by the webserver):
Because all of the necessary Source information was included in the Transport, Network and Data Link layer headers, Device F is able to create all the required headers to send this response back to Device A. The response, encapsulated in headers will look like this:
Data Link (MAC)Layer 2
Network (IP)Layer 3
Transport (TCP)Layer 4
If you compare the headers encapsulating the HTTP request against the headers encapsulating the HTTP response, you will notice that the Source and Destination fields are reversed depending on the direction the data is traveling (Device A → Device F vs Device A ← Device F).
The IP and Data-Link layer headers ensure that the HTTP response is correctly directed to Device A. When the response arrives at Device A, the response data is forwarded to the browser tab was assigned TCP port 10801. (This will be the same browser tab that had created the HTTP request.)
This concludes a synopsis of how data is transferred between 2 devices in a computer network. It leaves open 2 questions:
- Layer 1: We have discussed Layers 2 to 4 in our discussion, but we have not mentioned Layer 1. Does it exist in the model being used, and if so where does it fit in?
- Network devices: Switches, routers firewalls etc. Where do network devices fit in this process of data transfer. How do they affect the transfer of data from one device to another?
There does exist a Layer 1 in the OSI Model. Layer 1 standards and protocols define the details of how data is represented and signalled over the physical medium being used by a network interface. This layer is known as the physical layer. The physical layer may be a wired layer or a wireless layer. The IEEE 802.11 standard includes different options for signalling at the physical layer using a wireless medium. Multiple standards exist at the physical layer for signalling over a wired medium. Some of these include Ethernet physical layer standards such as 10BASE-T, 100BASE-T, 100BASE-FX etc.
The details of signalling at the physical layer falls somewhat outside the scope of the networking field per se, it falls more within the field of electrical or computer engineering. However, it is important to understand one of the features included in Ethernet (and other) standards at the physical layer. This feature is called Carrier Sense Multiple Access / Collision Detection (CSMA/CD). CSMA/CD will be discussed in a separate post.
The role of switches, routers and firewalls in a network
We have discussed how data is encapsulated in multiple headers in order to be transferred from an application (such as a web browser) on one device to another application (such as a web server) on a different device in a network. We have not described the role of network devices such as switches, routers and firewalls in ensuring that the data arrives at the correct destination device. We will discuss in our next blog post: The role of switches, routers and firewalls in a network
thanks for sharing these valuable content for free. you have a big heart n kudo's to the team.
Thanks for the feedback! Great to hear that the content helped to really connect the dots! ;)
Check out the first 2 lessons in this course (Routing Baiscs):
The lessons "Review Network Headers" and "Address Resolution Protocol" cover this exact question!