TCP vs UDP
Two flavors of Layer 4 transport. TCP gives reliability and order at the cost of latency; UDP gives speed with no safety net. Covers the 3-way handshake, ports, when to use each, and the protocols that pick the wrong one.
- TCP is the reliable, ordered, connection-based transport. Used for HTTP, SSH, SMTP: anything that can't tolerate missing data.
- UDP is fire-and-forget. Used for DNS, DHCP, VoIP, video: anything where speed beats reliability.
- Both use 16-bit port numbers (0 to 65535). Same numbers, different protocols (TCP/80 ≠ UDP/80).
Mental model
When your application sends data over the network, it has a choice: do you want reliable delivery in order (TCP) or fast, lightweight, no guarantees (UDP)?
- TCP wraps every byte in a sequence number, acknowledges delivery, retransmits on loss, and reassembles in order. Costs: extra packets, extra round-trips, latency.
- UDP just throws packets at the destination and forgets them. Costs: nothing, but if anything’s lost, reordered, or duplicated, your app has to handle it.
The choice is application-by-application. Browsers pick TCP. DNS picks UDP. VoIP picks UDP because a delayed audio packet is worse than a lost one: by the time you retransmit, the conversation moved on.
TCP: the 3-way handshake
Before TCP sends any data, it establishes a connection through three packets:
Client Server
│ ───── SYN (seq=100) ──────► │
│ ◄──── SYN-ACK (seq=500, ack=101) ── │
│ ───── ACK (ack=501) ──────► │
│ │
│ ◄────── application data ─────────► │
After this dance, both sides have synchronized sequence numbers and know the connection is established. Closing follows a similar 4-way FIN/ACK exchange.
UDP: there is no handshake
Client Server
│ ─── UDP datagram ──► │
│ │
│ ◄── UDP datagram (maybe) ─── │
That’s the whole protocol. No setup, no teardown, no ack. UDP’s job is to add the source and destination ports to a packet and get out of the way.
Header overhead
| Protocol | Header size | Why |
|---|---|---|
| TCP | 20 bytes (40 with options) | Sequence #, ack #, flags, window, etc. |
| UDP | 8 bytes | Just src port, dst port, length, checksum |
For tiny payloads, UDP’s 8-byte header is a meaningful efficiency win. For a 1-byte payload, TCP + IP need 40 bytes of headers; UDP + IP need 28.
Ports: the same on both protocols, but separately
A port is a 16-bit number (0 to 65535) tagged onto every TCP and UDP packet. The pair (IP + port) identifies a unique conversation endpoint.
| Range | Name | Purpose |
|---|---|---|
| 0 to 1023 | Well-known | Standard protocols (HTTP 80, SSH 22, DNS 53) |
| 1024 to 49151 | Registered | Vendor-assigned (Cisco TFTP, MS-SQL, etc.) |
| 49152 to 65535 | Ephemeral | Source ports the OS picks for outbound connections |
Key gotcha: TCP port 80 and UDP port 80 are different things. They share the number, not the conversation. Most well-known protocols are TCP, but DNS uses both (UDP for queries, TCP for zone transfers and big responses).
Common ports: memorize these
| Port | Protocol | Notes |
|---|---|---|
| 20, 21 | TCP | FTP (data, control) |
| 22 | TCP | SSH |
| 23 | TCP | Telnet (don’t use: unencrypted) |
| 25 | TCP | SMTP |
| 53 | UDP + TCP | DNS |
| 67, 68 | UDP | DHCP (server, client) |
| 69 | UDP | TFTP |
| 80 | TCP | HTTP |
| 110 | TCP | POP3 |
| 123 | UDP | NTP |
| 143 | TCP | IMAP |
| 161, 162 | UDP | SNMP (poll, trap) |
| 443 | TCP | HTTPS |
| 514 | UDP | Syslog |
| 3389 | TCP | RDP |
CCNA exam loves to ask about port numbers. Memorize the common ones.
When to use which
Use TCP when:
- Data must arrive intact and in order (web pages, files, email)
- You can tolerate slight latency for reliability
- The application doesn’t already handle loss
Use UDP when:
- Speed matters more than reliability (VoIP, video, online gaming)
- The application implements its own reliability (QUIC, TFTP)
- The query/response is tiny and a retransmit is cheaper than a connection setup (DNS)
Commands
See active TCP connections on a Cisco router
R1# show tcp brief
R1# show ip sockets
R1# show tcp statistics
Test reachability of a specific port
R1# telnet 10.0.0.1 80 ! quick "is the TCP port open?" test
If telnet connects, port 80 TCP is reachable. If it hangs or refuses, it’s not. (Doesn’t work for UDP: telnet is TCP-only.)
Common mistakes
Assuming HTTPS is UDP. It’s TCP, port 443. (TLS sits on top of TCP.) HTTP/3 uses UDP, but for CCNA, HTTPS = TCP/443.
Thinking SSH and Telnet share the same port. SSH is 22, Telnet is 23. Easy to confuse on the exam.
Forgetting DNS uses both. UDP/53 for normal queries (small response). TCP/53 for zone transfers and any response larger than ~512 bytes (EDNS now supports more in UDP, but TCP fallback still exists).
Forgetting source vs destination port direction. A client connecting to a web server uses an ephemeral source port (e.g. 49000) and destination port 80. The server’s reply has source 80, destination 49000. Mistakes here cause ACL rules to fail.
Using
telnetto test UDP ports. Doesn’t work: telnet is TCP only. For UDP, usenc -u host porton Linux or specific protocol clients.
Lab to try tonight
- Open Wireshark, start a capture.
- From your laptop, browse to any HTTPS site. Find the TCP 3-way handshake (SYN, SYN-ACK, ACK) in the capture.
- Also find a DNS query. Confirm it’s UDP/53.
- In a terminal:
nslookup -type=A google.comwhile capturing. See exactly one request and one response, both UDP/53. - Try
telnet google.com 443: connects (TCP/443 open). - Try
telnet 8.8.8.8 53: connects (DNS servers also listen on TCP/53 for large responses and zone transfers).
Cheat strip
| Concept | Plain English |
|---|---|
| TCP | Reliable, ordered, connection-based. HTTP, SSH, SMTP. |
| UDP | Fire-and-forget. DNS, DHCP, VoIP, video. |
| 3-way handshake | SYN → SYN-ACK → ACK (TCP only) |
| Sequence numbers | TCP uses them to reorder and detect loss |
| Port range 0 to 1023 | Well-known (HTTP 80, SSH 22, DNS 53) |
| Port range 49152+ | Ephemeral: client-side source ports |
| TCP/80 ≠ UDP/80 | Different conversations entirely |
| DNS uses both | UDP for queries, TCP for big responses + zone transfers |
Frequently asked questions
Q: When should I use TCP vs UDP? A: TCP when correctness matters more than latency: file transfer, web pages, email, SSH. UDP when latency matters more than correctness: voice, video, gaming, DNS queries. TCP guarantees delivery and ordering at the cost of retransmission delay; UDP just fires and forgets, leaving the application to handle any reliability it wants. If you don’t know which to pick, default to TCP.
Q: Why does DNS use both UDP and TCP? A: UDP for normal queries (small, one round-trip, retry-if-lost is fine): over 99% of DNS traffic is UDP 53. TCP for zone transfers between servers (large payloads) and for responses larger than 512 bytes (which happens with DNSSEC signatures, big TXT records, etc.). Modern clients also use TCP-fallback when the UDP response has the TC (truncated) flag set.
Q: Does UDP have a checksum? A: Yes, but in IPv4 it’s optional (a checksum of zero means “not calculated”). In IPv6 the UDP checksum is mandatory. In practice virtually every implementation sets it because Ethernet’s CRC only catches errors in-frame, errors introduced by intermediate devices or memory would sail through without a UDP checksum. If you see UDP-checksum-zero, it’s almost always a middlebox stripping it.
Q: What’s QUIC and how does it relate to TCP/UDP? A: QUIC is a transport protocol built on UDP that provides reliable, ordered, encrypted, multiplexed delivery: effectively “TCP replacement” without the TCP handshake latency and without head-of-line blocking. Google runs the majority of google.com traffic over QUIC (HTTP/3 = HTTP over QUIC). From the network’s perspective it’s UDP on port 443; from the application’s perspective it behaves like TCP+TLS.
Q: Why does TCP have a three-way handshake? A: To synchronize the initial sequence numbers in both directions and confirm both sides can send and receive. SYN (client) → SYN-ACK (server acknowledges + sends its own SYN) → ACK (client acknowledges server’s SYN). Two-way isn’t enough because you need each side to confirm it received the other’s sequence number. This is also what SYN-flood attacks abuse, half-opening thousands of connections and never sending the final ACK, exhausting the server’s connection table.
Practice: quick check
Every question in the bank, once. No repeats. Missed ones cycle back at the end.
Private IPv4 Addressing (RFC 1918)
The three private IPv4 ranges (10/8, 172.16/12 and 192.168/16) reserved for internal networks, hidden behind NAT and never routable on the public internet.
Interface & Cable Issues: Collisions, Errors, Duplex/Speed Mismatch
Late collisions, input errors, CRC counters, and the classic auto-negotiation trap where one side ends up half-duplex and the link crawls at a fraction of its rated speed.
Want this drilled into reflex?
1:1 weekly sessions, live feedback on your labs, and US interview prep: built around the CCNA® exam blueprint. Free first session. No card on file until you decide.
Related topics
DHCP: Dynamic Host Configuration Protocol
CCNA DHCP guide: the DORA exchange, packet anatomy, DHCP options, T1/T2 lease renewal, Cisco IOS server and relay config, DHCP Snooping and 8 scenarios.
IP ServicesDNS: Domain Name System
How www.example.com becomes an IP address. Covers the recursive query path (root → TLD → authoritative), record types (A, AAAA, CNAME, MX, PTR), TTL caching, and the most common DNS failure modes.
Network FundamentalsOSI Model & TCP/IP
Two networking reference models compared side-by-side. The seven OSI layers, the four TCP/IP layers, and which one the real internet actually runs on (spoiler: not OSI).
Get the free CCNA 12-week roadmap
You're already reading up on TCP vs UDP. The roadmap is the order I recommend studying every CCNA topic in: with what to lab each week and where TCP vs UDP fits. A written personal reply, not an autoresponder. Expect it within one business day.
Personal reply from a senior network engineer. No third-party tracking. Unsubscribe any time.
