A Beginner's Guide to TCP vs UDP Protocols

A Beginner's Guide to TCP vs UDP Protocols

Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) are foundation pillars of a Internet for sending data from one device to another device.

What Is TCP (Transmission Control Protocol)?

TCP is one of the foundational protocol of transport layer which is responsible for end-to-end data transfer between devices. It is a reliable, ordered and connection-oriented protocol that ensures accurate delivery of data transfer.

Working of TCP

TCP works by using a “three-way handshake” — a three-step process that forms a connection between a device and a server. The completion of the three-step process establishes the non-stop connection, starts the transfer of data packets across the internet, delivers them intact, and acknowledges delivery.

Here’s how TCP works:

  1. The client device initiating the data transfer sends a sequence number (SYN) to the server. It tells the server the number that the data packet transfer should begin with.

  2. The server acknowledges the client SYN and sends its own SYN number. This step is often referred to as SYN-ACK (SYN acknowledgement).

  3. The client then acknowledges (ACK) the server’s SYN-ACK, which forms a direct connection and begins the data transfer.

The connection between the sender and receiver is maintained until the transfer is successful. Every time a data packet is sent, it requires an acknowledgment from the receiver. So, if no acknowledgment is received, the data is resent.

You can also understand the above diagram with following real world example:

The TCP “three-way handshake” is similar to what we do while we start talking to someone on mobile phones.

  1. The first person says “HELLO” to second person starting the conversation.

  2. The second person sends replies with “HELLO” and acknowledge with “YOUR VOICE IS CLEAR”.

  3. The first person acknowledge second person message by saying “YUP YOU ARE ALSO CLEAR” and now they both are ready to start conversation.

Application of TCP

We use TCP protocol when we want to ensure that the receiver received all the data packets and in ordered format like in the following services:

  • Email and text messages

  • Transferring files between apps and devices

  • Streaming pre-recorded content on sites like Netflix, Hulu, or HBO Max

What is UDP (User Datagram Protocol)?

UDP is another data transfer protocol of transport layer which is also responsible for end-to-end data transfers between devices. It is faster, unreliable, unordered and connectionless protocol that sends data without establishing a connection, prioritise speed over reliability.

Working of UDP

The UDP protocol works by immediately firing data at the receiver who made a transmission request, until the transmission is completed or terminated. For this reason sometimes the UDP protocol is also called a fire-and-forgot protocol. UDP fires data to the recipient in no particular sequence and also it does not conform whether the packets are delivered or check if they are arrived as intended.

While TCP establishes the a formal data connection between devices via “handshake” for transferring data. The UDP protocol does not establish any connection. It just speed up the process of data transfer by sending packets to the receiver without making any agreement. It is then up to the recipient to the make the sense of the data.

You can again understand the above diagram with following real world example:

  1. The Second person initiates the communication by sending “HELLO” to the first person.

  2. Now, the first person sends messages to the second person without waiting for any acknowledgment.

  3. Messages are send continuously without conforming whether they are received or not.

  4. Some messages are dropped (indicated by … ), and the order of received messages is not guaranteed.

  5. This represents UDP's characteristics: fast but unreliable communication without ensuring delivery or order.

Applications of UDP

  1. Online gaming

  2. Video chatting/conferencing

  3. Domain Name Systems