# TCP vs UDP

The internet is a **huge global network** made up of millions of computers, servers, routers, and cables.  
For all these different machines—built by different companies, running different operating systems, and located in different countries—to communicate smoothly, **they must follow common rules**.

These rules are called **protocols**.

Without rules, data sent from one computer might be misunderstood, lost, duplicated, or arrive in the wrong order. Protocols define **how data is packaged, addressed, transmitted, received, and interpreted** across the network.

For example:

* **IP (Internet Protocol)** decides **where data should go**
    
* **TCP and UDP** decide **how data is delivered**
    
* **DNS** decides **how names are translated into addresses**
    
* **HTTP/HTTPS** decide **how web data is requested and served**
    

Together, these protocols ensure that when you send a message, open a website, or stream a video, the data reaches the correct destination **reliably, efficiently, and securely**.

👉 In short, **the internet works because everyone follows the same set of rules for sending data**.**<mark>What are TCP and UDP</mark>**

**TCP** and **UDP** are **transport-layer protocols** that decide **how data is sent between computers over a network**. **They control how data travels from one device to another.**

## TCP (Transmission Control Protocol)

### 🔹 What TCP does

TCP provides **reliable, ordered, and error-checked delivery** of data.

### Features

* Connection-oriented (3-way handshake)
    
* Guarantees data delivery
    
* Maintains correct order
    
* Retransmits lost data
    
* Slower but reliable
    

### Used in

* Websites (HTTP/HTTPS)
    
* Emails
    
* File transfers
    
* APIs
    

---

## UDP (User Datagram Protocol)

### 🔹 What UDP does

UDP sends data **without checking delivery or order**.

### Features

* Connectionless
    
* No guarantee of delivery
    
* No retransmission
    
* Very fast
    
* Low overhead
    

### Used in

* Video streaming
    
* Online gaming
    
* Voice calls (VoIP)
    
* Live broadcasts
    

---

## 🆚 **<mark> TCP vs UDP (Quick Comparison)</mark>**

| Feature | TCP | UDP |
| --- | --- | --- |
| Connection | Required | Not required |
| Reliability | Guaranteed | Not guaranteed |
| Speed | Slower | Faster |
| Order | Preserved | Not preserved |
| Use case | Accuracy | Speed |

---

## Simple analogy

* TCP = registered post (safe & tracked)
    
* UDP = normal post (fast but no tracking)
    

---

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769694095354/a4da5f4f-6b6e-4eae-b789-8ff05567edf1.png align="center")

1. ## **<mark>When to use TCP</mark>**
    

Use TCP (Transmission Control Protocol) **<mark>when data integrity, accuracy, and ordered delivery are critical</mark>**, such as for web browsing (HTTP/HTTPS), file transfers (FTP), email (SMTP/IMAP), and secure shell (SSH) access. It is ideal for applications that cannot tolerate packet loss or data corruption, ensuring reliable, connection-oriented communication. 

**Key Scenarios for Using TCP:**

* **Web Browsing (HTTP/HTTPS):** Essential for loading webpages correctly, ensuring no data is missing or corrupted.
    
* **File Transfers (FTP/SFTP):** Ensures files (like software downloads) are transmitted accurately without errors.
    
* **Email (SMTP, POP, IMAP):** Guarantees messages and attachments are delivered fully.
    
* **Remote Administration (SSH, Telnet):** Requires a reliable, persistent, and ordered stream of data for commands.
    
* **Database Connections:** Crucial for applications where data accuracy is paramount, such as SQL queries. 
    

**Why Choose TCP?**

* **Reliability:** TCP provides error checking, retransmission of lost packets, and guarantees data delivery.
    
* **Ordered Delivery:** It ensures packets arrive in the correct sequence.
    
* **Connection-Oriented:** A stable session is established before data is exchanged. 
    

**When Not to Use TCP:**  
Avoid TCP for real-time, low-latency applications like live voice/video streaming or online gaming, where speed is more important than losing a few packets. In those cases, [**UDP**](https://www.geeksforgeeks.org/computer-networks/when-is-udp-preferred-to-tcp/) is preferred

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769694635222/74718476-af3a-4f97-bbdc-fc00840d4bda.png align="center")

## **<mark>When to use UDP</mark>**

**UDP (User Datagram Protocol)** should be used when **speed and low latency matter more than perfect reliability**. Use UDP when it’s okay to lose some data, but not okay to be slow.

## Best situations to use UDP

### 1️⃣ Live video & audio streaming

* Zoom, Google Meet, YouTube Live
    
* Missing 1–2 frames is better than freezing
    

👉 UDP avoids delays caused by retransmissions.

---

### 2️⃣ Online gaming

* Multiplayer games need **real-time updates**
    
* Late data is useless
    

👉 Speed &gt; accuracy.

---

### 3️⃣ Voice over IP (VoIP)

* Internet calls
    
* Small packet loss is unnoticeable
    
* Delay is very noticeable
    

---

### 4️⃣ Real-time sensors & IoT

* Weather sensors
    
* GPS tracking
    
* Live telemetry
    

👉 Data is continuously updated.

---

### 5️⃣ Broadcasting & Multicasting

* Live sports
    
* TV streaming
    
* One sender → many receivers
    

👉 UDP is efficient for this.

---

### 6️⃣ Simple request–response protocols

Examples:

* **DNS**
    
* **DHCP**
    
* **SNMP**
    

👉 Small, fast messages.

---

## Common real-world examples of TCP vs UDP

  
When NOT to use UDP

* File downloads
    
* Emails
    
* Banking transactions
    
* Web pages where accuracy matters
    

Use **TCP** instead.

---

## Simple analogy

* UDP = live phone call (some words may drop)
    
* TCP = email or courier (everything must arrive)
    

---

## **<mark>Common real-world examples of TCP vs UDP</mark>**

TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) serve different needs: TCP provides reliable, ordered, and error-checked delivery (ideal for accuracy), while UDP offers fast, connectionless, and lightweight transmission (ideal for speed). Common TCP examples include **<mark>web browsing (HTTP/HTTPS), email (SMTP), and file transfers (FTP)</mark>**. UDP is used for real-time applications like online gaming, VoIP, and live video streaming. 

**Real-World Examples of TCP (Reliability Focus)** 

* **Web Browsing (HTTP/HTTPS):** When loading web pages, all data must arrive accurately to display properly.
    
* **File Transfer (FTP, SFTP):** Ensuring files (like documents or software downloads) are not corrupted during transfer.
    
* **Email (SMTP, IMAP, POP):** Guaranteeing that an email is delivered exactly as sent.
    
* **Remote Desktop/SSH:** Securely managing remote servers where command accuracy is critical.
    
* **Streaming Content (Netflix/YouTube):** Using buffering to ensure high-quality playback, prioritizing complete data over real-time speed. 
    

**Real-World Examples of UDP (Speed/Latency Focus)** 

* **Online Gaming (Fortnite, Call of Duty):** Fast updates are more important than receiving every single packet; if a packet is lost, the game simply waits for the next update.
    
* **Video Conferencing (Zoom, Skype, WhatsApp):** Real-time, two-way communication requires low latency; occasional minor audio/video glitches are better than high lag.
    
* **Voice over IP (VoIP):** Similar to video conferencing, speed is prioritized for smooth audio.
    
* **DNS (Domain Name System):** Resolving website names to IP addresses quickly to initiate fast web browsing.
    
* **Live Sports Streaming:** Real-time data delivery is more important than perfect picture quality, preferring lower latency. 
    

**Key Differences Summary**

* [**TCP**](https://www.google.com/search?q=TCP&sca_esv=e8f5b2d100cbb45b&biw=1280&bih=551&aic=0&sxsrf=ANbL-n7qfzMh3FvLL56g3juM-Vll8DRoeg%3A1769694464656&ei=AGV7adHgJ5-OseMPlvOD4QQ&ved=2ahUKEwi4wfDZ87CSAxW_RmcHHSauPa0QgK4QegQICRAB&uact=5&oq=Common+real-world+examples+of+TCP+vs+UDP%0D%0A%0D%0A&gs_lp=Egxnd3Mtd2l6LXNlcnAiKkNvbW1vbiByZWFsLXdvcmxkIGV4YW1wbGVzIG9mIFRDUCB2cyBVRFAKCjIHECMYJxjqAjIHECMYJxjqAjIHECMYJxjqAjINECMY8AUYJxjJAhjqAjIHECMYJxjqAjINECMY8AUYJxjJAhjqAjIHECMYJxjqAjIHECMYJxjqAjIHECMYJxjqAjIHECMYJxjqAjIXEAAYgAQYkQIYtAIY5wYYigUY6gLYAQEyFxAAGIAEGJECGLQCGOcGGIoFGOoC2AEBMhcQABiABBiRAhi0AhjnBhiKBRjqAtgBATIXEAAYgAQYkQIYtAIY5wYYigUY6gLYAQEyFxAAGIAEGJECGLQCGOcGGIoFGOoC2AEBMhcQABiABBiRAhi0AhjnBhiKBRjqAtgBAUilD1DiBVjiBXABeAGQAQCYAQCgAQCqAQC4AQPIAQD4AQH4AQKYAgGgAg6oAhCYAw7xBca_nIhtmGutugYGCAEQARgBkgcBMaAHALIHALgHAMIHAzMtMcgHCYAIAA&sclient=gws-wiz-serp&mstk=AUtExfDUVRjnI3YQxdRzjDqKAhjfFA3vRQ_Sf3Md0c1JvPZlcDRmYQD7aUymv3WVFZSDXLcZRZ8GWf4HN5pYqWdUghuwXEizk8ZVttlaTOgpjzVgwrRENWg3CeogwX5r0gOLLlQtmbyaatidEDbaeuJrh_3D-3HEwOQ7zkoOvNX7U264DMqzkqOkmIs-Sp7hwXrqofiNekDZwZprYhCRUMURpX111cnt8uzzekUFDEq0-EHCxdLvVHop7k37uEDNQx1DUpx4kpPv5TB_gPPnsGPakleRyBIjEUWAa1tMQR-4xvboPJL1NWf_TXBSUzNRhsmF5MocPxEG-vSx4W2FY9ITibTByaXVGtGRsff_Bal8yFzy08eXHYxBlSZdW9ByYQqw5i6nidJHswbm5wTor7U0enYqk2ngtymxD4UTtGrxAmgIzhwr9l1FkT09AtGLO7tb&csui=3)**:** Connection-oriented, retransmits lost packets, slower.
    
* [**UDP**](https://www.google.com/search?q=UDP&sca_esv=e8f5b2d100cbb45b&biw=1280&bih=551&aic=0&sxsrf=ANbL-n7qfzMh3FvLL56g3juM-Vll8DRoeg%3A1769694464656&ei=AGV7adHgJ5-OseMPlvOD4QQ&ved=2ahUKEwi4wfDZ87CSAxW_RmcHHSauPa0QgK4QegQICRAD&uact=5&oq=Common+real-world+examples+of+TCP+vs+UDP%0D%0A%0D%0A&gs_lp=Egxnd3Mtd2l6LXNlcnAiKkNvbW1vbiByZWFsLXdvcmxkIGV4YW1wbGVzIG9mIFRDUCB2cyBVRFAKCjIHECMYJxjqAjIHECMYJxjqAjIHECMYJxjqAjINECMY8AUYJxjJAhjqAjIHECMYJxjqAjINECMY8AUYJxjJAhjqAjIHECMYJxjqAjIHECMYJxjqAjIHECMYJxjqAjIHECMYJxjqAjIXEAAYgAQYkQIYtAIY5wYYigUY6gLYAQEyFxAAGIAEGJECGLQCGOcGGIoFGOoC2AEBMhcQABiABBiRAhi0AhjnBhiKBRjqAtgBATIXEAAYgAQYkQIYtAIY5wYYigUY6gLYAQEyFxAAGIAEGJECGLQCGOcGGIoFGOoC2AEBMhcQABiABBiRAhi0AhjnBhiKBRjqAtgBAUilD1DiBVjiBXABeAGQAQCYAQCgAQCqAQC4AQPIAQD4AQH4AQKYAgGgAg6oAhCYAw7xBca_nIhtmGutugYGCAEQARgBkgcBMaAHALIHALgHAMIHAzMtMcgHCYAIAA&sclient=gws-wiz-serp&mstk=AUtExfDUVRjnI3YQxdRzjDqKAhjfFA3vRQ_Sf3Md0c1JvPZlcDRmYQD7aUymv3WVFZSDXLcZRZ8GWf4HN5pYqWdUghuwXEizk8ZVttlaTOgpjzVgwrRENWg3CeogwX5r0gOLLlQtmbyaatidEDbaeuJrh_3D-3HEwOQ7zkoOvNX7U264DMqzkqOkmIs-Sp7hwXrqofiNekDZwZprYhCRUMURpX111cnt8uzzekUFDEq0-EHCxdLvVHop7k37uEDNQx1DUpx4kpPv5TB_gPPnsGPakleRyBIjEUWAa1tMQR-4xvboPJL1NWf_TXBSUzNRhsmF5MocPxEG-vSx4W2FY9ITibTByaXVGtGRsff_Bal8yFzy08eXHYxBlSZdW9ByYQqw5i6nidJHswbm5wTor7U0enYqk2ngtymxD4UTtGrxAmgIzhwr9l1FkT09AtGLO7tb&csui=3)**:** Connectionless, no retransmission, faster. 
    
    ## **<mark>What is HTTP and where it fits</mark>**
    
    #### What is HTTP?
    
    **HTTP (Hyper Text Transfer Protocol)** is a **set of rules** that defines **how web clients and web servers communicate**. **HTTP is the language used by browsers and servers to talk on the web.**
    
    ## What HTTP Does
    
    HTTP defines:
    
    * How a **request** is sent (GET, POST, etc.)
        
    * How a **response** is returned
        
    * Status codes (200, 404, 500)
        
    * Headers and body structure
        
    
    Example:
    
    ```plaintext
    Browser → HTTP Request → Server
    Browser ← HTTP Response ← Server
    ```
    
    ---
    
    ## Where HTTP Fits in the Internet Stack
    
    HTTP does **not send data itself**. It sits **on top of other protocols**.
    
    ```plaintext
    Application Layer   → HTTP / HTTPS
    Transport Layer     → TCP (or QUIC for HTTP/3)
    Internet Layer      → IP
    Network Layer       → Ethernet / Wi-Fi
    ```
    
    👉 HTTP focuses on **what is being sent**, not **how it physically travels**.
    
    ---
    
    ## HTTP vs HTTPS
    
    * **HTTP** → data in plain text
        
    * **HTTPS** → HTTP + TLS encryption (secure)
        
    
    Modern web always uses **HTTPS**.
    
    ---
    
    ## Where HTTP is used
    
    * Websites
        
    * REST APIs
        
    * Mobile apps
        
    * Microservices
        
    
    ---
    
    ## Simple analogy
    
    * HTTP = language of conversation
        
    * TCP = delivery service
        
    * IP = address system
        
    
    ---
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769695595720/ab6e844f-d319-42b6-821a-fddfbdb4ff2a.png align="center")

## **<mark>Relationship between TCP and HTTP</mark>**

An HTTP request flows over a TCP connection **<mark>by first establishing a reliable, connection-oriented tunnel via a three-way handshake (SYN, SYN-ACK, ACK)</mark>**. Once connected, the client sends HTTP data (request line, headers, body) as a stream of bytes through this TCP socket. The server processes this request and sends back a response, utilizing the same TCP connection. 

**Key Aspects of the HTTP/TCP Flow:**

* **Connection Establishment:** Before any data is sent, the browser/client initiates a TCP connection with the server (usually on port 80 for HTTP or 443 for HTTPS).
    
* **Data Transmission:** The HTTP request (e.g., `GET / HTTP/1.1`) is transmitted in TCP packets, which are guaranteed to arrive in order and without errors.
    
* **Packetization:** The HTTP request data is broken into segments, transmitted across the network, and reassembled at the destination.
    
* **Connection Persistence:** Modern HTTP (1.1+) uses persistent connections to reuse the same TCP connection for multiple requests, reducing latency.
    
* **Closing the Connection:** The connection is either closed by the client/server after the response is complete or kept open for subsequent requests. 
    

**Steps in the Flow:** 

1. [**DNS Lookup**](https://www.google.com/search?sca_esv=e8f5b2d100cbb45b&sxsrf=ANbL-n7i84u265Bfb410LNI5NsjlaS-2TQ%3A1769695614148&q=DNS+Lookup&source=lnms&fbs=ADc_l-aN0CWEZBOHjofHoaMMDiKpaEWjvZ2Py1XXV8d8KvlI3izfzqgn7395CNCvYdZRuZ4-lOsJlglncpOd_-CGga6cOLqDKZIowtVXUSv9JiBkrDj_EVKMNnAlL9U6nYgzJP4iv6sQzj8tIFPpc0hvgoc4YumyWxmscKDKsCQfl0vdGvj741GEr57TdBxmmZqHP29jgv3juYo7vuOEF-nTzHWzB5uvq5uZPCg39rVv-k8Le2AUqKg&sa=X&ved=2ahUKEwiAhr319bCSAxVI1DgGHfs0JnkQgK4QegQIBhAB&biw=1280&bih=551&dpr=1.5&aic=0&mstk=AUtExfD2wX0ZfHJIS3I2glLg9TMT8SPCCCfNWwvehT6o307Or44dvx_X1pWo7tJv-_2zMTvta88WDlDYbrz_GMY8KJN-pffwgCcYzoi_NLD_90ku5NSp8URxTZX8txcpe5DbV50etU1mUc-KFQ1nAyuHXAYzIXWPGIS8rXMNRY2lG7E4FOe2s27tQ7-ByE0iMD5r-e3CCUtZvRJ6udqfRwlYPkFjtXFySGooAlu8AvJm95bFox8aLoc5O2sET0bMmmobolsEeykud24Q7fdHU9nQQjIZ7HsFtzKefD7kjtpnesyTqLEXV_ZcbII7HqovYjWXjlvpwTweH0s3SkceV4y4d2kVnwk_16xc9YUW4zuIeVE7vzi3RfM0TWrrv_041EVzK_VjBFaaq-FJrMzJ_ABocA8IznePC1zPLSxL9vRSdSBOiTR29mswbIGtPTp-S1b-&csui=3)**:** The browser resolves the URL to an IP address.
    
2. [**TCP Handshake**](https://www.google.com/search?sca_esv=e8f5b2d100cbb45b&sxsrf=ANbL-n7i84u265Bfb410LNI5NsjlaS-2TQ%3A1769695614148&q=TCP+Handshake&source=lnms&fbs=ADc_l-aN0CWEZBOHjofHoaMMDiKpaEWjvZ2Py1XXV8d8KvlI3izfzqgn7395CNCvYdZRuZ4-lOsJlglncpOd_-CGga6cOLqDKZIowtVXUSv9JiBkrDj_EVKMNnAlL9U6nYgzJP4iv6sQzj8tIFPpc0hvgoc4YumyWxmscKDKsCQfl0vdGvj741GEr57TdBxmmZqHP29jgv3juYo7vuOEF-nTzHWzB5uvq5uZPCg39rVv-k8Le2AUqKg&sa=X&ved=2ahUKEwiAhr319bCSAxVI1DgGHfs0JnkQgK4QegQIBhAD&biw=1280&bih=551&dpr=1.5&aic=0&mstk=AUtExfD2wX0ZfHJIS3I2glLg9TMT8SPCCCfNWwvehT6o307Or44dvx_X1pWo7tJv-_2zMTvta88WDlDYbrz_GMY8KJN-pffwgCcYzoi_NLD_90ku5NSp8URxTZX8txcpe5DbV50etU1mUc-KFQ1nAyuHXAYzIXWPGIS8rXMNRY2lG7E4FOe2s27tQ7-ByE0iMD5r-e3CCUtZvRJ6udqfRwlYPkFjtXFySGooAlu8AvJm95bFox8aLoc5O2sET0bMmmobolsEeykud24Q7fdHU9nQQjIZ7HsFtzKefD7kjtpnesyTqLEXV_ZcbII7HqovYjWXjlvpwTweH0s3SkceV4y4d2kVnwk_16xc9YUW4zuIeVE7vzi3RfM0TWrrv_041EVzK_VjBFaaq-FJrMzJ_ABocA8IznePC1zPLSxL9vRSdSBOiTR29mswbIGtPTp-S1b-&csui=3)**:** A three-way connection is established (SYN →right arrow→ SYN-ACK →right arrow→ ACK).
    
3. [**HTTP Request**](https://www.google.com/search?sca_esv=e8f5b2d100cbb45b&sxsrf=ANbL-n7i84u265Bfb410LNI5NsjlaS-2TQ%3A1769695614148&q=HTTP+Request&source=lnms&fbs=ADc_l-aN0CWEZBOHjofHoaMMDiKpaEWjvZ2Py1XXV8d8KvlI3izfzqgn7395CNCvYdZRuZ4-lOsJlglncpOd_-CGga6cOLqDKZIowtVXUSv9JiBkrDj_EVKMNnAlL9U6nYgzJP4iv6sQzj8tIFPpc0hvgoc4YumyWxmscKDKsCQfl0vdGvj741GEr57TdBxmmZqHP29jgv3juYo7vuOEF-nTzHWzB5uvq5uZPCg39rVv-k8Le2AUqKg&sa=X&ved=2ahUKEwiAhr319bCSAxVI1DgGHfs0JnkQgK4QegQIBhAH&biw=1280&bih=551&dpr=1.5&aic=0&mstk=AUtExfD2wX0ZfHJIS3I2glLg9TMT8SPCCCfNWwvehT6o307Or44dvx_X1pWo7tJv-_2zMTvta88WDlDYbrz_GMY8KJN-pffwgCcYzoi_NLD_90ku5NSp8URxTZX8txcpe5DbV50etU1mUc-KFQ1nAyuHXAYzIXWPGIS8rXMNRY2lG7E4FOe2s27tQ7-ByE0iMD5r-e3CCUtZvRJ6udqfRwlYPkFjtXFySGooAlu8AvJm95bFox8aLoc5O2sET0bMmmobolsEeykud24Q7fdHU9nQQjIZ7HsFtzKefD7kjtpnesyTqLEXV_ZcbII7HqovYjWXjlvpwTweH0s3SkceV4y4d2kVnwk_16xc9YUW4zuIeVE7vzi3RfM0TWrrv_041EVzK_VjBFaaq-FJrMzJ_ABocA8IznePC1zPLSxL9vRSdSBOiTR29mswbIGtPTp-S1b-&csui=3)**:** The browser sends the formatted HTTP request (method, headers, body).
    
4. [**Server Processing**](https://www.google.com/search?sca_esv=e8f5b2d100cbb45b&sxsrf=ANbL-n7i84u265Bfb410LNI5NsjlaS-2TQ%3A1769695614148&q=Server+Processing&source=lnms&fbs=ADc_l-aN0CWEZBOHjofHoaMMDiKpaEWjvZ2Py1XXV8d8KvlI3izfzqgn7395CNCvYdZRuZ4-lOsJlglncpOd_-CGga6cOLqDKZIowtVXUSv9JiBkrDj_EVKMNnAlL9U6nYgzJP4iv6sQzj8tIFPpc0hvgoc4YumyWxmscKDKsCQfl0vdGvj741GEr57TdBxmmZqHP29jgv3juYo7vuOEF-nTzHWzB5uvq5uZPCg39rVv-k8Le2AUqKg&sa=X&ved=2ahUKEwiAhr319bCSAxVI1DgGHfs0JnkQgK4QegQIBhAJ&biw=1280&bih=551&dpr=1.5&aic=0&mstk=AUtExfD2wX0ZfHJIS3I2glLg9TMT8SPCCCfNWwvehT6o307Or44dvx_X1pWo7tJv-_2zMTvta88WDlDYbrz_GMY8KJN-pffwgCcYzoi_NLD_90ku5NSp8URxTZX8txcpe5DbV50etU1mUc-KFQ1nAyuHXAYzIXWPGIS8rXMNRY2lG7E4FOe2s27tQ7-ByE0iMD5r-e3CCUtZvRJ6udqfRwlYPkFjtXFySGooAlu8AvJm95bFox8aLoc5O2sET0bMmmobolsEeykud24Q7fdHU9nQQjIZ7HsFtzKefD7kjtpnesyTqLEXV_ZcbII7HqovYjWXjlvpwTweH0s3SkceV4y4d2kVnwk_16xc9YUW4zuIeVE7vzi3RfM0TWrrv_041EVzK_VjBFaaq-FJrMzJ_ABocA8IznePC1zPLSxL9vRSdSBOiTR29mswbIGtPTp-S1b-&csui=3)**:** The server receives, parses, and processes the request.
    
5. [**HTTP Response**](https://www.google.com/search?sca_esv=e8f5b2d100cbb45b&sxsrf=ANbL-n7i84u265Bfb410LNI5NsjlaS-2TQ%3A1769695614148&q=HTTP+Response&source=lnms&fbs=ADc_l-aN0CWEZBOHjofHoaMMDiKpaEWjvZ2Py1XXV8d8KvlI3izfzqgn7395CNCvYdZRuZ4-lOsJlglncpOd_-CGga6cOLqDKZIowtVXUSv9JiBkrDj_EVKMNnAlL9U6nYgzJP4iv6sQzj8tIFPpc0hvgoc4YumyWxmscKDKsCQfl0vdGvj741GEr57TdBxmmZqHP29jgv3juYo7vuOEF-nTzHWzB5uvq5uZPCg39rVv-k8Le2AUqKg&sa=X&ved=2ahUKEwiAhr319bCSAxVI1DgGHfs0JnkQgK4QegQIBhAL&biw=1280&bih=551&dpr=1.5&aic=0&mstk=AUtExfD2wX0ZfHJIS3I2glLg9TMT8SPCCCfNWwvehT6o307Or44dvx_X1pWo7tJv-_2zMTvta88WDlDYbrz_GMY8KJN-pffwgCcYzoi_NLD_90ku5NSp8URxTZX8txcpe5DbV50etU1mUc-KFQ1nAyuHXAYzIXWPGIS8rXMNRY2lG7E4FOe2s27tQ7-ByE0iMD5r-e3CCUtZvRJ6udqfRwlYPkFjtXFySGooAlu8AvJm95bFox8aLoc5O2sET0bMmmobolsEeykud24Q7fdHU9nQQjIZ7HsFtzKefD7kjtpnesyTqLEXV_ZcbII7HqovYjWXjlvpwTweH0s3SkceV4y4d2kVnwk_16xc9YUW4zuIeVE7vzi3RfM0TWrrv_041EVzK_VjBFaaq-FJrMzJ_ABocA8IznePC1zPLSxL9vRSdSBOiTR29mswbIGtPTp-S1b-&csui=3)**:** The server sends back the requested data.
    
6. [**Connection Closure/Re-use**](https://www.google.com/search?sca_esv=e8f5b2d100cbb45b&sxsrf=ANbL-n7i84u265Bfb410LNI5NsjlaS-2TQ%3A1769695614148&q=Connection+Closure%2FRe-use&source=lnms&fbs=ADc_l-aN0CWEZBOHjofHoaMMDiKpaEWjvZ2Py1XXV8d8KvlI3izfzqgn7395CNCvYdZRuZ4-lOsJlglncpOd_-CGga6cOLqDKZIowtVXUSv9JiBkrDj_EVKMNnAlL9U6nYgzJP4iv6sQzj8tIFPpc0hvgoc4YumyWxmscKDKsCQfl0vdGvj741GEr57TdBxmmZqHP29jgv3juYo7vuOEF-nTzHWzB5uvq5uZPCg39rVv-k8Le2AUqKg&sa=X&ved=2ahUKEwiAhr319bCSAxVI1DgGHfs0JnkQgK4QegQIBhAN&biw=1280&bih=551&dpr=1.5&aic=0&mstk=AUtExfD2wX0ZfHJIS3I2glLg9TMT8SPCCCfNWwvehT6o307Or44dvx_X1pWo7tJv-_2zMTvta88WDlDYbrz_GMY8KJN-pffwgCcYzoi_NLD_90ku5NSp8URxTZX8txcpe5DbV50etU1mUc-KFQ1nAyuHXAYzIXWPGIS8rXMNRY2lG7E4FOe2s27tQ7-ByE0iMD5r-e3CCUtZvRJ6udqfRwlYPkFjtXFySGooAlu8AvJm95bFox8aLoc5O2sET0bMmmobolsEeykud24Q7fdHU9nQQjIZ7HsFtzKefD7kjtpnesyTqLEXV_ZcbII7HqovYjWXjlvpwTweH0s3SkceV4y4d2kVnwk_16xc9YUW4zuIeVE7vzi3RfM0TWrrv_041EVzK_VjBFaaq-FJrMzJ_ABocA8IznePC1zPLSxL9vRSdSBOiTR29mswbIGtPTp-S1b-&csui=3)**:** The connection is terminated or reused for further requests. 
    
    ## **<mark>Relationship between TCP and HTTP</mark>**
    
    **HTTP and TCP work together**, but they do **different jobs** in the internet stack. HTTP defines *what* is sent, TCP defines *how* it is delivered reliably.
    
    ## Where They Fit (Layered View)
    
    ```plaintext
    Application Layer   → HTTP
    Transport Layer     → TCP
    Internet Layer      → IP
    ```
    
    * **HTTP** sits at the **application layer**
        
    * **TCP** sits at the **transport layer**
        
    
    HTTP **depends on TCP** to move its data.
    
    ---
    
    ## How HTTP Uses TCP (Step-by-Step)
    
    1. Browser wants a web page
        
    2. **TCP connection is established** (3-way handshake)
        
    3. **HTTP request** is sent over that TCP connection
        
    4. Server sends **HTTP response**
        
    5. TCP ensures:
        
        * Data arrives
            
        * Data is in order
            
        * Lost packets are retransmitted
            
    6. Connection is closed or reused
        
    
    ---
    
    ## Why HTTP Needs TCP
    
    TCP provides:
    
    * **Reliability** (no lost data)
        
    * **Correct order**
        
    * **Error detection**
        
    * **Flow control**
        
    
    Web pages must load **correctly**, not partially—so TCP is ideal.
    
    ---
    
    ## What HTTP does NOT do
    
    HTTP does **not**:
    
    * Handle packet loss
        
    * Guarantee delivery
        
    * Manage connections
        
    
    That’s **TCP’s job**.
    
    ---
    
    ## HTTP over TCP vs HTTP over UDP
    
    * **HTTP/1.1 & HTTP/2** → use **TCP**
        
    * **HTTP/3** → uses **QUIC (built on UDP)** for lower latency
        
    
    ---
    
    ## Simple analogy
    
    * HTTP = message content
        
    * TCP = reliable courier
        
    * IP = address system
