TCP and UDP: What are the Differences between TCP and UDP?

Have you ever heard about the TCP and UDP network protocols and wondered what the differences are? Read this article right now to find out!

TCP and UDP are the two primary protocols of the transport layer of the TCP/IP model.
Often TCP is called the “reliable” protocol, and UDP is called the “unreliable” protocol.

But what actually are the differences between those protocols, and why do we even need an “unreliable” connection?

Keep reading to find an answer to those questions, and find out more about the advantages and disadvantages of both protocols!

TCP (Transmission Control Protocol)

How does it work?

We consider TCP the more reliable protocol because it makes sure that a connection between devices is up and the target device receives every single set of data correctly.

TCP is a connection-oriented protocol. Hence, TCP performs a three-way handshake to make sure that both devices are ready for the data transfer. After the handshake has been performed successfully, the sending computer splits the data into segments and assigns numbers to them. Now, the target computer can receive those segments of data and order them correctly. Additionally, both computers calculate a checksum. If the checksums of both computers match, all data was received. If not, the sending computer simply resends the missing data segments.

The Three-Way Handshake works the following way:
First, the computer that wants to establish a connection, sends a SYN (Synchronization) flag to the target computer. Next, the target computer should reply with a SYN-ACK (Synchronization-Acknowledge) flag to accept the connection. Finally, the source computer responds again with a final ACK (Acknowledge) flag to symbolize it is ready too and will start to send data.

Three-way handshake
What does the TCP header look like?
What does the TCP header look like

The header describes the payload and its information of data transmission to help other devices know how to handle the data.

The header size of a TCP header is 20 bytes (excluding optional data).

Advantages of TCP
  • Data doesn’t get lost easily (reliable)
  • TCP makes sure the data reaches the destination the same way it was sent
  • connection-oriented
  • provides an error-checking and recovery mechanism
  • data can be sent as well as received (full-duplex)
  • avoids data congestion (the receiving computer can control the speed at which the data is sent)
Disadvantages of TCP
  • higher latency
  • slow handshake at the beginning of each connection
Examples of TCP Applications
  • web browsing (HTTP)
  • file transfer (FTP)
  • text communication

UDP (User Datagram Protocol)

How does it work?

Compared to TCP, UDP is rather unreliable. That is because UDP is not connection-oriented (connectionless) and doesn’t care whether the target computer is receiving all data.

There is no sequencing, no recovery of lost data, and no three-way handshake. The only purpose of UDP is to send data, no matter whether it gets lost.

Even though lost data will not be recovered, both computers calculate a checksum to at least know if data has been lost.

How the UDP protocol works
What does the UDP header look like?
What a UDP header looks like

The header describes the payload and its information of data transmission to help other devices know how to handle the data.

The header size of UDP is 8 bytes (excluding data).

Advantages of UDP
  • fast data transfer
  • does not need a connection to be established and maintained
  • provides error detection
  • smaller header and packet size (faster and more memory efficient)
Disadvantages of UDP
  • unreliable
  • no recovery of lost data
  • no flow control / congestion control
  • data could be received in the wrong order
Examples of UDP Applications
  • live streams
  • phone calls
  • online games
  • Domain Name System (DNS)

Direct comparison between TCP and UDP

TCP (Transmission Control Protocol) UDP (User Datagram Protocol)
Connection type connection-oriented → a connection needs to be established before the source computer starts to transfer data connectionless → no connection is needed for the source computer to send data
Reliability more reliable because of sequencing, flow control, error checking, and data recovery less reliable
Speed  slower  faster
Header size  20 bytes 8 bytes
Acknowledgement  Performs a three-way handshake doesn’t care about acknowledgement → just sends data
Flow control makes sure the data is sent at an appropriate speed not to cause congestion there is no flow control mechanism → UDP just sends the data at any speed
Error checking & Data recovery checks for errors using a checksum and resends lost or corrupted data checks for errors using a checksum but doesn’t resend lost data
Use cases TCP is mainly used where reliability is more important than speed. (e.g. web browsing, file transfer, etc.) UDP is mainly used where fast connections are needed and reliability doesn’t matter very much. (e.g. live video streams, online games, etc.)

Thanks for reading!

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *