Difference between TCP and UDP Protocols 

Transmission Control Protocol and User Datagram Protocol are the two internet protocol traffic used for sending bits of data known as packets over the Internet.

Simply we can say it as whether you are sending a packet via TCP or UDP, that packet is sent to an IP address. These packets are treated similarly, as they are forwarded from your computer to intermediary routers and on to the destination.

How TCP Works?

When you are going to load a web page, your system sends TCP packets to the web server’s address, asking it to send the web page to you. So the web server responds to it by sending a stream of TCP packets, which your web browser stitches together to form the web page and display it to you.

When you click on a link and do actions like sign in, post a comment, or do anything else, your web browser sends TCP packets to the server and the server sends TCP packets back.

TCP takes care about your data so it is not just one way communication instead  the remote system sends packets back to acknowledge it is received your packets so that no data is lost or corrupted in transition.

How UDP Works?

The UDP protocol works similarly to TCP, but it throws all the error-checking stuff out. Here the packets are just sent to the recipient and the sender will not wait to make sure that the recipient received the complete packet or not.It will just continue sending the next packets.

If you are the recipient and if you miss some UDP packets, later you can not ask for those packets again. But losing all this overhead means the system can communicate more quickly.

So this kind of protocols are used  under live broadcasts and online games.

Let's look in to some major difference between these 2 protocols:



1. TCP will rearranges the data packets in the same way as it was sent

1. UDP has no inherent order as all packets are independent of each other.

2. TCP is heavy weight, So it requires three packets to set up a socket connection, before any user data can be sent. It handles reliability and congestion control.

2. UDP is lightweight. So there is no ordering of messages, no tracking connections, etc.Moreover It is a small transport layer designed on top of IP.

3. It’s header size is 20 bytes.

3. It’s header size is 8 bytes.

4. TCP does Flow Control.

4. UDP does not have an option for flow control.

5. It will allow to do the  error checking and error recovery. Error packets are retransmitted from the source to the destination.

5. It also does the error checking but simply discards erroneous packets. Error recovery is not attempted.

6. It is guaranteed that the data transferred remains intact and arrives in the same order in which it was sent.

6. There is no guarantee that the messages or packets sent would reach at all.