TCP vs UDP · Lesson 4 of 8 · 4 min read
Comparison and protocol mapping
TCP vs UDP
| TCP | UDP | |
|---|---|---|
| Connection | Handshake, connection state | None |
| Reliability | ACKs, retransmission | None (application's job) |
| Ordering | Guaranteed | Not guaranteed |
| Boundaries | Byte stream | Datagram boundaries kept |
| Flow/congestion control | Yes | No |
| Header | 20–60 bytes | 8 bytes |
| Overhead / latency | Higher (handshake, ACKs, HOL blocking) | Lower |
| Broadcast/multicast | No | Yes |
| Unit | Segment | Datagram |
Analogy: TCP is a tracked courier — numbered parcels, signatures, redelivery of anything lost, delivered in order. UDP is dropping postcards in a mailbox — cheap and quick, but some may never arrive and they may arrive out of order.
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.
Which protocol uses what
| Protocol | Transport | Port |
|---|---|---|
| HTTP/1.1, HTTP/2, HTTPS | TCP | 80, 443 |
| HTTP/3 | UDP (QUIC) | 443 |
| SSH, SFTP, SCP | TCP | 22 |
| SMTP | TCP | 25 / 587 / 465 |
| DNS | UDP 53, TCP 53 for large responses and zone transfers; DoT TCP 853, DoH TCP/UDP 443 | 53 |
| DHCP | UDP | 67 (server) / 68 (client) |
| NTP | UDP | 123 |
| SNMP | UDP | 161, traps 162 |
| Syslog | UDP 514 traditionally; TCP/TLS (6514) for reliability | 514 |
| gRPC | TCP (HTTP/2) | — |
| Databases (MySQL, Postgres, Redis, Mongo) | TCP | 3306, 5432, 6379, 27017 |
| Kafka | TCP | 9092 |
| WireGuard | UDP | 51820 |
| OpenVPN | UDP (or TCP) | 1194 |
| VXLAN (overlays, Swarm) | UDP | 4789 |
| Kubernetes API / kubelet | TCP | 6443 / 10250 |
DNS: the protocol that uses both
DNS queries go over UDP 53 because they're small and a retry is cheaper than a handshake. It uses TCP 53 when:
- a response doesn't fit (the server sets the TC — truncated — flag and the client retries over TCP), increasingly common with DNSSEC signatures and many records;
- zone transfers (AXFR/IXFR) between primary and secondary servers;
- DNS over TLS (853) and some modern resolvers prefer TCP.
So firewalls and security groups must allow both UDP and TCP 53 to resolvers. A firewall that allows only TCP 53 breaks most lookups; one that allows only UDP 53 breaks large responses intermittently — a nasty, hard-to-spot failure.
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.