# TCP and UDP

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

- Level: Intermediate
- Topics: Networks
- URL: https://tidbit.legios.com.ar/tcp-and-udp/
- In Spanish: [TCP y UDP](https://tidbit.legios.com.ar/es/tcp-and-udp/)

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.

## An analogy

TCP is a phone conversation with confirmation: did you get that? yes, go on; repeat if not. UDP is shouting across a stadium: fast, no confirmation, and if a word gets lost you do not stop the game to repeat it.

## Keep in mind

- TCP: connection, ordering, retransmission. Reliable but with some delay.
- UDP: no connection, no retries. Fast and simple; losing a packet is acceptable.
- Web, email and APIs use TCP; calls, streaming, games and DNS use UDP.
- HTTP/3 runs over UDP (QUIC) and brings its own reliability.

## Go deeper

- [What is TCP/IP? (Cloudflare)](https://www.cloudflare.com/learning/ddos/glossary/tcp-ip/)
- [What is UDP? (Cloudflare)](https://www.cloudflare.com/learning/ddos/glossary/user-datagram-protocol-udp/)
- [RFC 9293: Transmission Control Protocol](https://datatracker.ietf.org/doc/html/rfc9293)

## Related terms

- [IP address](https://tidbit.legios.com.ar/ip-address/): The number that identifies a device on a network, like a postal address.
- [Packet](https://tidbit.legios.com.ar/packet/): The small chunk every piece of internet data is cut into before it travels.
- [Internet](https://tidbit.legios.com.ar/internet/): A worldwide network of networks that lets any connected device reach any other.
- [Port](https://tidbit.legios.com.ar/port/): The numbered door on a computer that says which program a connection is for.
- [HTTP](https://tidbit.legios.com.ar/http/): The request-and-response language browsers and websites speak.
- [HTTPS](https://tidbit.legios.com.ar/https/): The padlock in your browser: web traffic nobody in between can read.
- [API](https://tidbit.legios.com.ar/api/): The menu of things one program lets another program ask for.
- [DNS](https://tidbit.legios.com.ar/dns/): The internet's phone book: it turns names like wikipedia.org into IP addresses.
