# TCP vs UDP

---

Lets introduce the contenders

## UDP ( User Datagram Protocol )

lightweight, connectionless transport layer protocol (Layer 4) designed for speed and efficiency over IP networks

By eliminating connection handshakes and error correction, it enables fast, real-time data transmission

It is said to be less reliable as it does not prevent data loss nor it ensures order

## TCP ( Transmission Control Protocol )

read prev blog on TCP - [https://toddlerstech.hashnode.dev/tcp-transfer-control-protocol-and](https://toddlerstech.hashnode.dev/tcp-transfer-control-protocol-and)

in summary it is reliable as it ensures prevention of data loss and ordered data is being transferred and inferred slow as compared to UDP .

---

## Think first

do you feel that UDP being so less reliable should not be made in the first place is there any task in which it can be used . why anyone will want data loss ?? think carefully

---

## Applications

### TCP

* **Web Browsing:** HTTP and HTTPS protocols rely on TCP to ensure all parts of a webpage (text, images) are delivered correctly.
    
* **File Transfer (FTP/SFTP):** Used to transfer files without loss or corruption.
    
* **Email (SMTP, IMAP, POP3):** Ensures that email messages are fully transmitted and not corrupted.
    
* **Remote Access (SSH, Telnet):** Requires a reliable connection for issuing commands.
    
* **Database Connectivity:** Ensuring database queries and data are accurately transmitted.
    

Till now you may agree with all TCP uses but may not be able to think one for UDP. Don’t worry Here are some of them

### UDP

* **Live Streaming/Video Conferencing:** Protocols like RTP or SRT are used because dropping a few video frames is better than pausing for retransmission.
    
* **Voice over IP (VoIP):** Real-time voice calls (e.g., Skype, Zoom) use UDP to reduce lag.
    
* **Online Gaming:** Fast-paced games use UDP for real-time updates where speed is crucial, and lost packets are immediately replaced by newer data.
    
* **DNS (Domain Name System):** UDP is used for fast, quick requests to resolve domain names.
    
* **DHCP (Dynamic Host Configuration Protocol):** For fast IP address assignment.
    

This may light the bulb , every time we do not require reliability , data protection . Sometimes these just ruin user experience . Here we want fast and smooth experience even if some data never reach us .

---

## HTTP

this may look like a detour but it is not .

HTTP is Hyper Text transfer Language Protocol . Another protocol in the debate ? Fortunately no .

HTTP is **the foundation of data communication for the World Wide Web, serving as an application-layer protocol for transmitting hypermedia documents, such as HTML**. It enables, via a **request-response model**, browsers to request, and servers to return, web resources. Key versions include HTTP/1.1, HTTP/2, and the QUIC-based HTTP/3.

![Beginner Introduction to OSI Model and HTTP Protocol | by Issath Sesni |  Medium](https://miro.medium.com/v2/resize:fit:1400/1*2CG-g0bEW1OffPHWnk8uaQ.jpeg align="left")

as you can see in the above diagram , HTTP works at top most layer and TCP / UDP works at Transport Layer.

I want to say that HTTP is not in the competition . It actually uses either TCP / UDP to transfer data from server to client or vice versa.

This is a common doubt of beginners as many jargons end with Protocol so they think they belong to same bucket . But it is not the case generally.

---

## Who won ?

well after reading this blog you might have a slight hint that TCP and UDP don’t play in same type of battlefield . Both are used in modern day world , it depends on the use case whether TCP or UDP is used .

---
