TCP vs UDP: what's the difference?
TCP and UDP are the two main ways data travels over the internet. TCP is reliable but slower; UDP is fast but lossy. Here's when each one is used.
On this page
- What they have in common
- How TCP works: the reliable option
- How UDP works: the fast option
- Comparison table
- When to use TCP
- When to use UDP
- A real-world example
- FAQ
- Which is faster, TCP or UDP?
- Can TCP and UDP use the same port number?
- Why is UDP used for video calls and online games?
- Which is more reliable, TCP or UDP?
- Summary
TCP and UDP are the two main transport protocols of the internet. TCP (Transmission Control Protocol) guarantees that data arrives complete and in order — at the cost of speed. UDP (User Datagram Protocol) sends data fast without guarantees — packets can be lost, reordered, or duplicated. Web pages, email, and file transfers use TCP. Video calls, online games, and DNS lookups use UDP.
What they have in common
Both protocols run on top of IP (Internet Protocol). IP delivers packets to the right address, but it does not handle packet ordering or error checking — that is exactly the gap TCP and UDP fill differently. Both also use port numbers to tell a computer which application a packet belongs to, so a server can run many services at once.
How TCP works: the reliable option
TCP lets two hosts connect and exchange a stream of data. Before anything is sent, the two computers establish a connection with a three-way handshake:
- The source sends a SYN packet to start the dialogue.
- The target replies with SYN-ACK to agree.
- The source sends ACK to confirm — after which the data can flow.
TCP then guarantees the delivery of packets in the same order they were sent. If a packet goes missing, TCP asks for it to be re-sent. It also performs congestion control: transfers start small and grow until they reach what the network can support. This reliability is why email, web browsing, and file downloads use TCP — a corrupted download is useless.
How UDP works: the fast option
UDP is a connectionless protocol. There is no handshake, no connection setup: one computer simply starts sending data. UDP packets are called datagrams, and each one is addressed and sent independently. UDP provides checksums for data integrity and port numbers for addressing, but it does not guarantee delivery, ordering, or duplicate protection — that burden moves to the application.
The trade-off is speed. Without handshakes, retransmissions, and ordering bookkeeping, UDP is much faster and adds far less overhead. That makes it ideal for time-sensitive traffic, where dropping a packet is better than waiting for a delayed retransmission.
Comparison table
| TCP | UDP | |
|---|---|---|
| Connection | Connection-oriented (handshake first) | Connectionless (send immediately) |
| Handshake | Yes — 3-way (SYN, SYN-ACK, ACK) | No |
| Delivery guarantee | Yes — packets arrive complete, in order | No — loss, reordering, duplication possible |
| Retransmission | Lost packets are re-sent | Lost packets stay lost |
| Congestion control | Yes — starts small, grows | No |
| Speed / overhead | Slower, more overhead | Faster, minimal overhead |
| Typical use | Web, email, file transfer | VoIP, video, gaming, DNS |
When to use TCP
Use TCP whenever the data must arrive complete and in the right order:
- Web pages (HTTP/HTTPS)
- Email (SMTP, IMAP)
- File transfers
- Anything where a partial result is useless
When to use UDP
Use UDP whenever speed matters more than perfection, and the application can tolerate some loss:
- VoIP phone calls — a slightly static-y call beats a crystal-clear but delayed one
- Video streaming and conferencing
- Online gaming
- DNS lookups — they need to be fast and efficient
A real-world example
Loading a web page uses TCP: the page's bytes must arrive intact, in order, or the page is broken. A video call uses UDP: frames travel as fast as possible, and the occasional dropped frame just produces a tiny flicker — nobody wants the call to pause while a missing frame is re-sent.
FAQ
Which is faster, TCP or UDP?
UDP is faster. It has no handshake, no retransmission, and no ordering bookkeeping, so it adds far less overhead than TCP. That raw speed is why UDP is chosen for time-sensitive traffic where a dropped packet is better than waiting for a delayed retransmission.
Can TCP and UDP use the same port number?
Yes. Both protocols use port numbers to tell a computer which application a packet belongs to, and a server can run many services at once. Because TCP and UDP are separate protocols, a TCP connection and a UDP socket can use the same port number simultaneously without conflicting.
Why is UDP used for video calls and online games?
Because those applications are time-sensitive. Video calls, conferencing, and online games care more about low latency than about perfect delivery — an occasional lost frame or packet just causes a small flicker, whereas waiting for a delayed retransmission would make the call or game feel unresponsive.
Which is more reliable, TCP or UDP?
TCP. It establishes a connection with a three-way handshake, guarantees packets arrive complete and in order, and re-sends anything that goes missing. UDP provides no such guarantees — packets can be lost, reordered, or duplicated — which is why web pages, email, and file transfers use TCP.
Summary
TCP and UDP solve the same problem — moving data over IP — with opposite priorities. TCP guarantees delivery and order, and pays for it with handshakes, retransmissions, and overhead. UDP trades all guarantees for raw speed. Pick TCP when completeness matters; pick UDP when latency matters more.
Sources
- MDN — TCP (developer.mozilla.org/docs/Glossary/TCP)
- MDN — UDP (developer.mozilla.org/docs/Glossary/UDP)
- Cloudflare Learning Center — What is TCP/IP? (cloudflare.com/learning/ddos/glossary/tcp-ip)
- Cloudflare Learning Center — What is UDP? (cloudflare.com/learning/ddos/glossary/user-datagram-protocol-udp)
Share this guide
Related guides
- What is HTTP/3? A plain explanation
The newest version of HTTP runs on QUIC, a transport built on UDP instead of TCP. Here's what changes — and why pages feel faster with it.
- What are WebSockets? A plain explanation
WebSockets keep a two-way connection between browser and server open, so either side can send data any time. Here's how the handshake, frames, and close codes work — and when to use them.
- OSI model explained: the 7 layers of networking
The OSI model explained: what the 7 layers (physical to application) do, how data moves through them, and how the model compares with the real TCP/IP stack.