Networking

TCP vs UDP — Difference, When to Use, and Real-World Examples

TCP vs UDP explained — reliability, speed, headers, handshakes, and when to use each. Comparison table, real-world examples (video calls, gaming, HTTP), and quick answers to common questions.

TCP and UDP are two of the most important transport layer protocols in computer networks. Understanding the difference between them is essential for CBSE Class 11 and 12 Computer Science exams, where networking carries significant marks.


What is TCP?

TCP (Transmission Control Protocol) is a connection-oriented protocol. Before data is sent, a connection is established between the sender and receiver using a process called the three-way handshake.

TCP guarantees that:

  • Data is delivered in the correct order, No data packets are lost, Errors are detected and corrupted packets are retransmitted

How the three-way handshake works:

  1. SYN, The client sends a synchronisation request to the server
  2. SYN-ACK, The server acknowledges and sends its own synchronisation request
  3. ACK, The client acknowledges, and the connection is established

Think of TCP like sending a registered letter through the post office, you get a confirmation that it was delivered.


What is UDP?

UDP (User Datagram Protocol) is a connectionless protocol. Data is sent without establishing a connection first. There is no guarantee of delivery, ordering, or error correction.

UDP is faster than TCP because it skips the handshake process and does not wait for acknowledgements.

Think of UDP like shouting a message across a room, you send it and hope the other person hears it, but you do not wait to confirm.


TCP vs UDP, Comparison Table

This table is frequently asked in CBSE board exams. Memorise it.

Feature TCP UDP
Full Form Transmission Control Protocol User Datagram Protocol
Connection Type Connection-oriented Connectionless
Reliability Reliable (guarantees delivery) Unreliable (no guarantee)
Ordering Data arrives in order No ordering guarantee
Speed Slower (due to overhead) Faster (minimal overhead)
Error Checking Yes, with retransmission Basic checksum only
Flow Control Yes No
Header Size 20 bytes (minimum) 8 bytes (fixed)
Handshake Three-way handshake No handshake
Data Unit Segment Datagram
Overhead High Low
Broadcasting Not supported Supported

When to Use TCP

TCP is used when data accuracy is more important than speed. If even one packet is lost or arrives out of order, the application breaks.

Real-world examples of TCP:

  • Web browsing (HTTP/HTTPS), A web page must load completely and correctly. Missing data would mean broken pages.
  • Email (SMTP, IMAP, POP3), Every word in an email must arrive exactly as sent.
  • File transfer (FTP), A downloaded file must be identical to the original. A single corrupt byte can make the file unusable.
  • Secure Shell (SSH), Remote login sessions require reliable, ordered data.

When to Use UDP

UDP is used when speed is more important than reliability. Losing a few packets is acceptable as long as the data keeps flowing.

Real-world examples of UDP:

  • Video streaming (YouTube, Netflix), A few dropped frames are not noticeable. Waiting for retransmission would cause buffering.
  • Online gaming, Real-time action games need instant data. A delayed packet is useless because the game has already moved on.
  • Voice calls (VoIP), A tiny gap in audio is less annoying than a delay caused by retransmission.
  • DNS lookups, A DNS query is a small, single request. If it fails, the application simply sends it again.
  • Live broadcasts, Live TV or radio streaming needs continuous flow without pauses.

Understanding with an Analogy

Scenario Protocol Why
Sending a legal document TCP Every page must arrive, in order, with no errors
Live cricket commentary on radio UDP A missed word is fine, delay is not acceptable
Downloading a software update TCP The file must be complete and uncorrupted
Video call with a friend UDP Slight quality drop is fine, lag is not acceptable

TCP and UDP in the OSI Model

Both TCP and UDP work at Layer 4 (Transport Layer) of the OSI model and Layer 3 (Transport Layer) of the TCP/IP model.

  • They sit above the Network Layer (IP) and below the Application Layer (HTTP, FTP, DNS), IP handles addressing and routing; TCP/UDP handle how data is delivered

Key point for exams: TCP and UDP both use port numbers to identify applications. For example:

  • HTTP uses port 80
  • HTTPS uses port 443
  • DNS uses port 53
  • FTP uses port 21

Diagrams for Board Exams

When answering in exams, draw this simple comparison:

TCP Communication:

Client          Server
  |--- SYN ------->|
  |<-- SYN-ACK ----|
  |--- ACK ------->|
  |--- Data ------>|
  |<-- ACK --------|
  |--- FIN ------->|
  |<-- ACK --------|

UDP Communication:

Client          Server
  |--- Data ------>|
  |--- Data ------>|
  |--- Data ------>|
  (no acknowledgement)

Common Exam Questions with Answers

Q1: State two differences between TCP and UDP. (2 marks)

Answer:

TCP UDP
Connection-oriented protocol, establishes a connection before data transfer Connectionless protocol, sends data without establishing a connection
Reliable, guarantees delivery of data in correct order Unreliable, no guarantee of delivery or ordering

Q2: Give one example each of an application that uses TCP and an application that uses UDP. Justify your answer. (3 marks)

Answer:

  • TCP example: File Transfer Protocol (FTP). FTP is used to transfer files between computers. The file must arrive completely and without errors, so TCP's reliability is essential.
  • UDP example: Video conferencing. In a video call, real-time delivery is more important than perfect accuracy. A few lost frames are acceptable, but delay caused by retransmission is not.

Q3: Why is UDP faster than TCP? (2 marks)

Answer: UDP is faster than TCP because it does not perform a three-way handshake before sending data, does not wait for acknowledgements from the receiver, and does not retransmit lost packets. This reduces overhead and allows data to be sent immediately.

Q4: What is a three-way handshake? (3 marks)

Answer: A three-way handshake is the process TCP uses to establish a connection before data transfer. It involves three steps:

  1. The client sends a SYN (synchronise) packet to the server
  2. The server replies with a SYN-ACK (synchronise-acknowledgement) packet
  3. The client sends an ACK (acknowledgement) packet

After these three steps, the connection is established and data transfer can begin.

Q5: Which protocol would you use for an online multiplayer game? Give a reason. (2 marks)

Answer: UDP would be used for an online multiplayer game. In real-time games, speed is more important than reliability. If a player's position data is delayed due to retransmission (as in TCP), the game would lag. UDP sends data immediately without waiting for acknowledgements, providing the low latency that games require.


Key Points to Remember

  1. TCP = Reliable but slower. Use when accuracy matters (file transfer, email, web).
  2. UDP = Fast but unreliable. Use when speed matters (streaming, gaming, voice calls).
  3. Both operate at the Transport Layer.
  4. TCP uses a three-way handshake; UDP does not.
  5. TCP header is 20 bytes minimum; UDP header is 8 bytes fixed.
  6. In exams, always support your answer with an example and justification.

Master this comparison and you will be prepared for any TCP/UDP question in your CBSE board exam.


Frequently Asked Questions

Is UDP always faster than TCP?

UDP has lower per-packet overhead (8-byte header vs TCP's 20+ bytes) and no handshake, so the initial connection is faster. But "faster" depends on the workload. On a clean network, TCP and UDP throughput are similar. On a lossy network, TCP slows down because it retransmits, while UDP keeps sending — at the cost of dropped data. If your application can't tolerate loss, UDP is not actually faster end-to-end because you'd need to rebuild reliability on top of it.

Does HTTP use TCP or UDP?

HTTP/1.1 and HTTP/2 use TCP. HTTP/3 — the newest version, used by Google, Facebook, and Cloudflare — uses UDP via QUIC. QUIC adds reliability and encryption inside UDP, getting the low-latency setup of UDP with the guarantees of TCP.

Does DNS use TCP or UDP?

DNS uses both. The standard query is sent over UDP (port 53) because it's small and fast. If the response is larger than 512 bytes (or for zone transfers), DNS falls back to TCP on the same port.

Does VoIP and video calling use TCP or UDP?

UDP. Voice and video are real-time — a 200ms-late packet is worse than a lost packet. UDP delivers what arrives immediately and the application interpolates over the gaps. Zoom, WhatsApp calls, Google Meet, and gaming all use UDP.

Does YouTube and Netflix use TCP or UDP?

Most video streaming (YouTube, Netflix on HTTPS) historically used TCP because the player buffers a few seconds ahead — reliability matters more than instant delivery. Newer streams using HTTP/3 ride on top of UDP via QUIC for faster connection setup.

What is the three-way handshake in TCP?

TCP establishes a connection in three steps: SYN (client says "I want to talk"), SYN-ACK (server says "OK, ready"), ACK (client confirms). Only after this handshake does data flow. This is what makes TCP reliable but slow to start.

Can I send TCP packets without acknowledgement?

No. TCP is reliable by design — every packet is acknowledged, and unacknowledged packets are retransmitted. If you want to skip acknowledgements, use UDP instead.

Is TCP or UDP better for online multiplayer games?

UDP, almost always. Action games need positions every 16-30ms; a retransmitted-but-late position is useless. Games typically use UDP and add their own lightweight ordering on top. Turn-based games (chess, card games) can use TCP because timing isn't critical.

What is the difference between connection-oriented and connectionless?

Connection-oriented (TCP) means the two sides set up a session before data flows, agree on parameters, and tear it down after. Connectionless (UDP) means each packet is independent — the sender just fires and forgets. UDP is like dropping a postcard in the mail; TCP is like a phone call.

Want to learn more?

Explore free chapter-wise notes with quizzes and code playground

Prefer watching over reading?

Subscribe for free.

Subscribe on YouTube