Firewall rules that must say TCP or UDP
Your team is writing firewall rules for a new server. It runs a website, a DNS service and a voice system. For each one, the rule must say TCP or UDP, not just a port number. If you pick the wrong protocol, the service breaks. So you need to know which protocol each application uses, and why.
The two protocols side by side
Ask what should happen after a loss. A file transfer needs the missing bytes recovered before it can reconstruct the file. A real-time voice application may choose to conceal or discard an old frame whose playback deadline has passed. A program using UDP can still implement retries, ordering and congestion control; those features simply are not supplied by UDP itself.
Compare the complete application protocol, not just the TCP or UDP header. QUIC builds reliable streams over UDP, while a failed TCP connection can still leave a download incomplete. Neither TCP nor bare UDP encrypts the application data by itself; HTTPS uses additional security protocols. Your design choice trades implementation work, overhead and delivery behaviour.
| TCP | UDP | |
|---|---|---|
| Connection | Connection-oriented: three-way handshake first | Connectionless: sends straight away |
| Delivery | Reliable: lost data is resent | Best effort: lost data stays lost |
| Order | Data is passed to the application in order | No ordering |
| Flow and congestion control | Yes (windowing) | No |
| Header size | 20–60 bytes | 8 bytes |
| Data unit | Segment (part of a byte stream) | Datagram (one separate message) |
| Broadcast and multicast | Not possible | Possible |
| Typical uses | Web, email, file transfer, SSH | Voice, video, DNS, DHCP, NTP, games |
How soon the first data arrives
Device key: Client (laptop)
Lines show the example’s network connections. Thick links: uplinks/WAN, as labelled. The coloured path and envelope follow the current step; its text identifies the sender, receiver and traffic type.
- 1. TCP, trip 1: the client asks to connect. No data yet.
- 2. TCP, trip 2: the server agrees. There is still no data.
- 3. TCP, trip 3: only now can the request be sent.
- 4. UDP, trip 1: the very first datagram already carries the question.
- 5. UDP, trip 2: the answer comes back, after just one round trip.
Why a video call prefers loss to delay
Neither protocol is “better”; each is a trade-off. TCP spends time and bandwidth to make sure every byte arrives, in order. UDP adds almost no overhead and leaves loss and ordering to the application.
For example, a voice application can conceal or discard a late frame to meet a playback deadline. UDP lets it make that choice; it does not guarantee that loss is harmless. An ordered TCP stream can delay delivery of later bytes while earlier bytes are recovered. The application's deadline and recovery design determine the visible effect.
Five questions that pick the protocol
Ask these questions about the application:
| Question | If yes |
|---|---|
| Must every byte arrive, exactly as sent? (files, web pages, logins) | TCP |
| Is late data useless? (live voice, video, games) | UDP |
| Is it one short question and answer? (DNS, NTP) | UDP |
| Must it reach many receivers at once, or a host with no address? (multicast, DHCP) | UDP |
| Is it a long transfer that should share the link fairly? | TCP |
Some services use both. Classic DNS supports UDP and TCP queries; TCP also supports zone transfers and fallback after truncation. HTTPS can use TCP 443, while HTTP/3 runs over QUIC on UDP 443.
That last point catches people out when writing firewall rules: a rule that permits only TCP 443 may still allow sites to load if the client and server support a TCP-based fallback. That fallback is not guaranteed for every application, and a working page does not prove that UDP 443 is permitted.
Counting TCP and UDP hits on an ACL
On a Cisco router, each access control list (ACL) rule names the protocol, so the match counters show how much traffic of each kind arrives. The output below is based on Cisco documentation, not captured from a lab device.
R1#show access-lists EDGE-IN Extended IP access list EDGE-IN 10 permit tcp any host 203.0.113.10 eq 443 (15230 matches) 20 permit udp any host 203.0.113.10 eq 443 (40112 matches) 30 permit udp any host 203.0.113.53 eq domain (9921 matches) 40 permit tcp any host 203.0.113.53 eq domain (37 matches)
eq domain means port 53) receives mostly UDP, plus a few TCP queries for large answers or zone transfers. Leaving out line 40 would break those large lookups.Test yourself on choosing TCP or UDP
A company backs up its database to a remote server every night. Which protocol fits best?
A video system must send the same stream to 200 screens at once using a single multicast address. Why does it use UDP rather than TCP?
A firewall allows UDP 53 to a DNS server, but not TCP 53. What might fail?
Technical references
RFC 9293: base TCP header, connection state, sequence space and delivery; RFC 768: UDP fields; RFC 8085: application responsibilities over UDP; RFC 9000: QUIC over UDP; RFC 7766: DNS over TCP.