TCP / IP Stack - Oversimplified for Web Developers 🌍🧑🏻‍💻
Tags: webdev, networking, backend, javascript
Published: 2023-08-10 09:11:48

**Here is the animated version for those of you who prefer interactive videos:**

{% embed https://youtu.be/SXinGsiAPzI %}

## Introduction
The TCP / IP model is a conceptual model of how communications are made over the internet, and is consists of 4 layers.

![Layers of TCP / IP](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wwdxwizwazzbjhbhn4yy.png)

## 1. The Application Layer

The **application layer** is the layer that **interacts directly with the end user**, providing the services and applications that allows user to access and use the network resources. 

They are software applications you use on your computer, such as web browsers, email clients and messaging apps.

![Example: Applications that allows Internet access](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fij3hjfry37jndo05dni.png)
![Example: web browser, messaging apps](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wd61lhry20lxigbs2a2r.png)

**These use protocols such as:**
- HTTPS
- DNS
- SMTP
- FTP
- SSH

## 2. The Transport Layer

The **transport layer** provides data transport services to and from the application layer. It offers two main options for data transportation: **reliable** and efficient or **unreliable** and fast.

This layer uses protocols like TCP to provide reliable communication between two devices, and UDP to provide fast but unreliable transmission. (More on these in my other articles)

The transport layer takes the application data (for eg an HTTP POST request) from the application layer and packages it into segments, which are then sent over the internet using port numbers.

![Structure of a TCP segment on a high level](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zlllsjmtj8zwfl4wclfj.png)

## 3. The Network Layer

This layer is responsible for **routing the data across multiple networks** and it uses protocols such as the IP protocol.

![ip protocol route.png](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vyqislfjkrsy7fb24d70.png)

It takes the data from the transport layer and packages it into packets, which are then sent over the Internet using IP addresses.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9jhg254thuhl5xy30dkp.png)

Think of it like a postal service that can deliver letters across the globe. 

It needs to know the destination and the best route to get there. The Internet layer uses IP addresses to identify different networks and determines the best path for data to travel across them. 

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ecs36r4auic983vcdq5p.png)


**The network layer is considered an unreliable protocol** as it does not guarantee the delivery of packets or their order. The reliability of communication is achieved by higher protocols such as TCP which use IP as their underlying transport mechanism.

## 4. The Link Layer

The **link layer** is responsible for **taking the raw bits of data from the physical layer**, and organizing them into frames, then moving data between devices that are physically connected.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xofalvmnpyq4s4lgwkyo.png)

Think of it like a postman that is delivering letters within the same neighborhood. The postman needs to know the addresses of the sender and the recipient, and also needs to make sure that the letters are properly packaged and labeled. 


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hddem30hbj0204dmqfs1.png)

In the same way, the data link layer uses frames to package data and add information such as source and destination MAC addresses to ensure it gets delivered to the correct device.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/33f4rr2myvrph3nofbhu.png)