ENES

TCP and UDP

Two ways to send packets: TCP checks everything arrives, UDP just sends and moves on.

Two lanes: in the TCP lane every packet gets an acknowledgement and a lost one is resent; in the UDP lane packets fly without confirmation and one is lost

IP gets packets to the right machine, but it promises nothing: packets can get lost, duplicated or arrive out of order. TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) are the two protocols that sit on top of IP and decide how much to care. Every connection on the internet uses one or the other, plus a port number to reach the right program.

TCP is reliable. It opens a connection with a three-step handshake, numbers every packet, waits for acknowledgements, resends what went missing and delivers everything in order. It also slows down when the network is congested. Web pages (HTTP, HTTPS), email, file transfers and almost every API use TCP, because a web page with a missing chunk is useless.

UDP is the opposite: no handshake, no acknowledgements, no retries. Each packet goes out on its own, and if it is lost, it is lost. That sounds worse, but it is exactly right when a late packet is as useless as a missing one: a video call, a live stream, an online game, a DNS lookup. Better to skip a frame than to freeze while waiting for it. HTTP/3, the newest version of the web's protocol, runs on top of UDP (through QUIC) and adds its own reliability, to avoid some of TCP's delays.

Keep in mind

Go deeper

Related terms

More in Networks