What are TCP and UDP? How do they work?

TCP and UDP explained in the most straightforward way possible.

What are TCP and UDP? How do they work?

I often get asked "what TCP and UDP are. How do they work? what is the difference between them" - so today in this post I will clarify those questions for you.

So first let's clarify what TCP and UDP are. In most simple terms They are two different protocols used for sending bits of data or also known as packets. TCP and UDP are not the only protocols that are out there. However, they are the most widely used ones. Understanding UDP is way easier if we know about TCP. So, Let's talk about TCP first.

What is TCP and How does it work?

TCP stands for Transmission Control Protocol and it is the most commonly used protocol on the Internet. When you load a webpage, your computer is sending TCP packets to the Web server address, asking it to send a Web page to you. Then the Web server responds by sending a stream of TCP packets, which are Web browser stages together to form the Web page that you see. The same happens once you, for example, click on a link or Sinding or post a comment on your Web browser, sends TCP packets to the Web server and the server sends TSP packets back. However, this is not one-way communication. The remote system sends packets back to acknowledge that it received your packets. So this is based on a three-way handshake.

TCP threeway handshake.jpg

And as the name says, a three-way handshake is consistent out of three steps. The first one is 'SYN', in this step The client wants to establish a connection with the server So it sends a segment with SYN. And what SYN stands for is synchronize sequence number, which informs the server that the client wants to start communication and with what sequence number it starts the segments with.

After the SYN step comes the 'SYN-ACK', which is the second step, and in this step, The host receives the server's SYN-ACK and sends an ACK-nowledge. and in the final level, the server receives ACK and the TCP socket connection is established.

This is just an example of TCP communication established between a client and a server. Once the data transfer starts, TCP guarantees the receiver will get the packets in order by numbering them. Then the server sends messages back to the sender, saying it received the messages or packets. If the sender does not get the correct response, it will resend the packets to ensure the sender got the packets. All of those packets are also checked for errors. So TCP is all about reliability and with TCP packets tracked, so no data is lost or corrupted in transit. That's why once you download the file, over the Internet, your file is working once you run it on your machine because it is being transferred with TCP, so all the packets will reach their destination without any errors.

What is UDP and how does It work?

UDP, on the other hand, stands for user datagram protocol, a datagram is the same thing as a packet of information. And UDP protocol works similarly to TCP, but it throws all the error-checking stuff out. That's why UDP is much faster. It is used when speed is desirable and error correction is not necessary. For example, UDP is frequently used for live broadcasts and online games. That's why UDP doesn't really care whether packets received their destination. It keeps sending the packets whether they are getting to the right place or not.

That's it for your TCP and UDP crash course. Don't forget to follow my blog and subscribe to the newsletter. Also, follow me on