Every packet that crosses a network has to be handed to the right program on the right machine, and something has to decide whether lost packets get resent. That job belongs to the transport layer, and two protocols do nearly all of it. Understanding why both exist, rather than memorizing a two-column table, is what makes the exam questions easy: each one is really asking whether the scenario needs completeness or timeliness. This guide covers the mechanics, the headers, the port numbers worth knowing and the traps that cost points on CompTIA Network+ and Cisco CCNA.
What is the difference between TCP and UDP?
The short version is in the table. Everything else in this article explains why each row is true.
| Feature | TCP | UDP |
|---|---|---|
| Connection | Connection-oriented (handshake first) | Connectionless (just send) |
| Reliability | Acknowledgements and retransmission | None; best-effort |
| Ordering | Sequence numbers reorder data | No ordering; datagrams may arrive in any order |
| Flow and congestion control | Yes (window, slow start, congestion avoidance) | No; the application must pace itself |
| Header size | 20 bytes minimum, up to 60 with options | 8 bytes, fixed |
| Data unit | Byte stream, sent in segments | Message-based datagrams with preserved boundaries |
| Delivery model | Unicast only | Unicast, broadcast and multicast |
| Checksum | Mandatory | Optional in IPv4, mandatory in IPv6 |
| Typical uses | Web, email, file transfer, SSH, databases | DNS queries, DHCP, VoIP, streaming, gaming, TFTP, SNMP |
| Defined in | RFC 9293 (obsoletes RFC 793) | RFC 768 |
Two rows deserve emphasis because they are misunderstood. First, TCP is a byte stream: it does not preserve message boundaries, so two writes of 100 bytes may arrive as one read of 200 bytes. UDP preserves boundaries, so one send produces one datagram. Second, “unreliable” does not mean “bad”. It means the protocol itself makes no promise, and the application chooses whether it cares.
Where do TCP and UDP fit in the stack?
Both live at Layer 4, the Transport layer of the OSI model, above IP (Layer 3, in either IPv4 or IPv6; see IPv4 vs IPv6) and below the application. IP delivers a packet to the right host; the transport layer delivers the data to the right process on that host using a port number. A conversation is identified by five values: protocol, source IP, source port, destination IP and destination port. That five-tuple is also exactly what a stateful firewall, a NATtable and Wireshark's “Conversations” view use to track traffic. If the layered model is still fuzzy, read our OSI model guide first, then come back.
How does the TCP three-way handshake work?
Before any application data moves, TCP synchronizes sequence numbers on both ends. Three segments do it:
- SYN: the client sends a segment with the SYN flag set and a randomly chosen initial sequence number (ISN).
- SYN-ACK: the server replies with SYN and ACK both set. The ACK acknowledges the client's ISN plus one; the SYN carries the server's own ISN.
- ACK: the client acknowledges the server's ISN plus one. The connection is now ESTABLISHED on both sides and data can flow.
Handshake on the wire
Client 10.0.0.5:51234 → Server 203.0.113.10:443 [SYN] Seq=1000
Server 203.0.113.10:443 → Client 10.0.0.5:51234 [SYN, ACK] Seq=7000 Ack=1001
Client 10.0.0.5:51234 → Server 203.0.113.10:443 [ACK] Seq=1001 Ack=7001
Sequence numbers here are illustrative; real ISNs are unpredictable by design. The source port 51234 is an ephemeral port picked by the client.
The handshake is why TCP connections cost one full round trip before the first byte of application data (more with TLS on top), and why a server can be attacked with a SYN flood: many SYNs with no final ACK leave half-open connections consuming memory. SYN cookies and rate limiting are the standard defenses. Seeing the connection states yourself is easy; netstat -an lists them as LISTEN, SYN_SENT, SYN_RECEIVED, ESTABLISHED and TIME_WAIT, among others.
How does TCP guarantee delivery and order?
Every byte in a TCP stream has a sequence number. The receiver sends back an acknowledgement number naming the next byte it expects. If an acknowledgement does not arrive before a retransmission timer expires, the sender resends. If the receiver gets segments out of order, it holds them in a buffer and reassembles by sequence number before passing data up. A receiver that sees a gap keeps acknowledging the last in-order byte, and three duplicate ACKs trigger a fast retransmit without waiting for the timer.
This machinery is why a web page loads intact even over a lossy Wi-Fi link, and also why a lossy link feels slow under TCP: each loss costs a retransmission and shrinks the sending rate. For an exam, the keywords map directly: sequencing, acknowledgement, retransmissionand checksum are all TCP answers; none of them applies to UDP's own mechanism.
What are flow control and congestion control?
These are two different protections that exam questions deliberately blur:
| Mechanism | Protects | How it works |
|---|---|---|
| Flow control | The receiver from being overwhelmed | The receiver advertises a window size in each ACK: how many bytes it can still buffer. The sender never has more unacknowledged data in flight than that window (sliding window). |
| Congestion control | The network from being overwhelmed | The sender keeps its own congestion window, starting small (slow start), growing, and cutting back when loss signals congestion. It sends no more than the smaller of the two windows. |
UDP has neither. A UDP sender can transmit as fast as the application produces data, which is why large UDP streams without their own rate control can starve other traffic, and why protocols built on UDP (QUIC, RTP with RTCP feedback) add congestion awareness at a higher layer.
How does a TCP connection close?
Closing is normally a four-segment exchange because each direction is shut down independently: one side sends FIN, the other ACKs it, then the other side sends its own FIN and receives a final ACK. The side that closes first lingers in TIME_WAIT for a short period so that stray delayed segments cannot be mistaken for a new connection. A connection can also be aborted instantly with a RST segment, which is what a host sends when it receives a segment for a port with nothing listening, or when it wants to drop a session without the polite exchange.
What do the TCP and UDP headers contain?
Header size is a favorite exam fact, and the contents explain the behavior:
| Field | TCP | UDP |
|---|---|---|
| Source and destination port | 16 bits each | 16 bits each |
| Sequence number | 32 bits | Not present |
| Acknowledgement number | 32 bits | Not present |
| Data offset and flags | Header length plus control flags: SYN, ACK, FIN, RST, PSH, URG and others | Not present |
| Window size | 16 bits (extendable with window scaling) | Not present |
| Length | Derived from the IP header | 16 bits (header plus data) |
| Checksum | 16 bits, mandatory | 16 bits, optional over IPv4 |
| Options | Variable (MSS, window scale, SACK, timestamps) | Not present |
| Total header | 20 to 60 bytes | 8 bytes |
Look at what UDP omits. No sequence numbers means it cannot reorder; no acknowledgement number means it cannot know what arrived; no flags means no connection state. Those missing fields are the missing features. On a 1,500-byte Ethernet MTU, the 12 extra header bytes TCP carries are small, but for tiny messages such as a DNS query, avoiding the handshake and extra segments is the real saving.
What does UDP actually give you?
Beyond port numbers and an optional checksum, UDP adds almost nothing to IP, and that is its design goal. It gives you three useful properties. First, no connection setup: the first datagram carries data. Second, no connection state on the server, so one UDP socket can serve enormous numbers of clients, which suits DNS and NTP. Third, broadcast and multicast: because there is no connection, one datagram can be addressed to many receivers, which is how DHCP discovery and many streaming and discovery protocols work.
What you must handle yourself: loss, duplication, reordering and rate. Applications that need some of those build only the pieces they want. RTP adds sequence numbers and timestamps so a player can reorder and conceal gaps; TFTP adds simple acknowledgement of each block; QUIC rebuilds a full reliable transport over UDP.
When is each protocol used?
The decision rule: if a late packet is still useful, use TCP; if a late packet is garbage, use UDP.
| Application | Transport | Why |
|---|---|---|
| Web (HTTP/1.1, HTTP/2, HTTPS) | TCP 80 / 443 | Pages must arrive complete and in order. |
| HTTP/3 | UDP 443 (via QUIC) | QUIC provides reliability per stream without TCP head-of-line blocking. |
| Email (SMTP, IMAP, POP3) | TCP | A corrupted message is unacceptable. |
| File transfer (FTP, SFTP, SCP) | TCP | Every byte must match. |
| SSH, RDP | TCP | Interactive sessions need ordered, reliable keystrokes and screens. |
| DNS queries | UDP 53 (TCP 53 for large replies and zone transfers) | One small question, one small answer; a handshake would double the cost. |
| DHCP | UDP 67 / 68 | Client has no IP yet and must broadcast. |
| VoIP and video calls | UDP (RTP media; SIP signaling can use TCP or UDP) | Late audio is useless; retransmitting it adds delay. |
| Live streaming and online gaming | Mostly UDP | Fresh state beats a perfect old state. |
| TFTP | UDP 69 | Minimal protocol for booting and firmware; it adds its own acknowledgements. |
| SNMP | UDP 161 / 162 | Small polls and traps; a missed poll is simply repeated. |
| NTP | UDP 123 | Timing needs low, predictable latency. |
| Syslog | UDP 514 by default (TCP optional) | Fire-and-forget logging; reliable options exist when needed. |
Notice that “streaming” is not purely UDP. Video-on-demand services often deliver chunks over HTTP, which means TCP or QUIC, and rely on buffering to hide delay. Live, interactive media is where raw UDP dominates.
Why does HTTP/3 use UDP?
This is a modern point worth knowing because it shows that “UDP is unreliable, TCP is reliable” is a statement about the protocol, not the application. QUIC (RFC 9000) is a transport that runs on UDP and supplies its own reliability, congestion control and mandatory TLS 1.3 encryption, and HTTP/3 (RFC 9114) runs on top of it. Two practical benefits drive the design. A QUIC connection can complete transport and cryptographic setup together, saving round trips. And because QUIC multiplexes independent streams, one lost packet only stalls the stream it belongs to, whereas with HTTP/2 over TCP a single lost segment stalls every stream sharing the connection. Using UDP also lets QUIC evolve in user space without waiting for operating systems and middleboxes to update their TCP implementations.
For the exam, remember the headline: HTTPS is TCP 443, HTTP/3 uses UDP 443, and a firewall that blocks UDP 443 simply makes browsers fall back to TCP.
Which port numbers should I memorize?
Ports are 16-bit numbers. IANA assigns 0 to 1023 as well-known ports, 1024 to 49151 as registered ports, and 49152 to 65535 as dynamic or private ports, which clients draw from for the source side of a connection. The server listens on a fixed port; the client picks a random high one. This list covers the large majority of exam questions:
| Port | Protocol | Service |
|---|---|---|
| 20 / 21 | TCP | FTP data / control |
| 22 | TCP | SSH, SFTP, SCP |
| 23 | TCP | Telnet (cleartext) |
| 25 | TCP | SMTP (server to server mail) |
| 53 | UDP and 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 agent queries / traps |
| 389 | TCP (and UDP) | LDAP |
| 443 | TCP (UDP for QUIC) | HTTPS |
| 445 | TCP | SMB file sharing |
| 514 | UDP | Syslog |
| 587 | TCP | SMTP message submission (with STARTTLS) |
| 636 | TCP | LDAPS |
| 3389 | TCP | RDP |
| 5060 / 5061 | TCP and UDP / TCP (TLS) | SIP / SIP over TLS |
A memory trick: cleartext protocols have a secure sibling. Telnet 23 became SSH 22, HTTP 80 became HTTPS 443, LDAP 389 became LDAPS 636, and secure mail uses TLS on the submission and retrieval ports. For the full list in cheat-sheet form, see the Network+ cheat sheet and the CCNA cheat sheet. The authoritative source is the IANA registry linked in the sources below.
How do I spot TCP and UDP in Wireshark and packet captures?
Reading a capture is the practical skill that makes the theory stick, and scenario questions often show a short capture excerpt. Wireshark's Protocol column names the transport, and the packet details pane expands the headers described above. These display filters are worth knowing:
| Display filter | What it shows |
|---|---|
tcp or udp | Only that transport |
tcp.port == 443 | TCP traffic with source or destination port 443 |
udp.port == 53 | DNS over UDP |
tcp.flags.syn == 1 && tcp.flags.ack == 0 | First packet of each handshake (connection attempts) |
tcp.flags.reset == 1 | Resets: refused connections or aborted sessions |
tcp.analysis.retransmission | Retransmitted segments, a sign of loss |
tcp.analysis.zero_window | A receiver that has stopped accepting data |
icmp | Includes “port unreachable” replies to closed UDP ports |
What to look for. A healthy TCP session starts with SYN, SYN-ACK, ACK. A SYN that repeats with no SYN-ACK points to a firewall dropping traffic or a dead host; a SYN answered with RST means the host is up but nothing listens on that port. Many retransmissions and duplicate ACKs point to loss on the path. A UDP flow has no handshake at all: you see a request datagram and, if the service is up, a response, and nothing in the protocol tells you whether a missing response was lost, dropped or never sent. Right-click a TCP packet and choose Follow TCP Stream to see the reassembled conversation, and use Statistics → Conversations to see each five-tuple with byte counts.
What are the common exam traps?
- “DNS is UDP.” Mostly, but zone transfers and large responses use TCP 53. If the question mentions transfers between servers, answer TCP.
- Flow control versus congestion control. Flow control protects the receiver (window size in ACKs). Congestion control protects the network. Choose by who is being protected.
- “UDP is faster so use it for file transfers.” Only if the application adds its own reliability. A plain file copy needs TCP.
- TFTP versus FTP. TFTP is UDP 69, simple, unauthenticated and used for boot images and device configs. FTP is TCP 20/21.
- DHCP ports. 67 is the server, 68 is the client; both UDP. Reversing them is a frequent distractor.
- SYN-ACK is one segment. The second handshake step is a single segment with both flags set, so a sequence listing it as two separate packets is wrong.
- Ping and traceroute. Ping uses ICMP, not TCP or UDP. Cisco IOS and Linux traceroute send UDP probes by default, while Windows
tracertuses ICMP echo. - Stateless versus stateful. UDP has no connection, but firewalls still track UDP flows by five-tuple with a timeout, so return traffic is allowed.
- Segment, datagram, packet. A TCP PDU is a segment; a UDP PDU is a datagram; both are carried inside an IP packet. Exams use these words precisely.
- Header sizes. UDP 8 bytes, TCP 20 minimum. Do not swap them.
How do Network+ and CCNA test this?
CompTIA Network+ N10-009 treats TCP versus UDP as foundation knowledge in Domain 1 (Networking Concepts), where you are expected to recognize ports, protocols and traffic types, and then reuses it in troubleshooting and security. Typical forms: match a port to a service and its protocol, pick the right transport for a described application, interpret a port-based firewall rule, and recognize connection problems from a described symptom. The sibling skill is addressing, covered in our subnetting guide, which together with ports forms most of the exam's calculation and recall load. See the full objective breakdown in the Network+ exam guide.
Cisco CCNA 200-301 lists “Compare TCP to UDP” as a named objective in Network Fundamentals, and then applies it in IP services and security: access control lists that permit or deny by protocol and port, NAT/PAT that rewrites ports, and routing protocols with their own transports. For example, OSPF runs directly over IP (protocol 89) and uses neither TCP nor UDP, while BGP runs over TCP 179, a favorite comparison. Our CCNA exam guide covers the full blueprint, and Network+ vs CCNA helps you decide which to take first.
TCP vs UDP practice questions with answers
Answer each one before you open it. For a timed bank of exam-style questions, use the Network+ practice exam or the CCNA practice exam.
1. Which transport protocol is connectionless, has an 8-byte header and provides no retransmission?
UDP. Its header holds only source port, destination port, length and checksum, 16 bits each. TCP needs at least 20 bytes and provides retransmission.
2. What is the correct order of the TCP three-way handshake?
SYN from the client, SYN-ACK from the server, then ACK from the client. The SYN-ACK carries two flags in one segment: the server acknowledges the client SYN and sends its own SYN.
3. A DHCP client broadcasts a request to find a server. Which transport and ports are used?
UDP, with port 67 on the server and port 68 on the client. DHCP uses UDP because the client has no IP address yet and so cannot hold a TCP connection, and broadcast is only possible with UDP.
4. A VoIP call has occasional choppy audio but never freezes for seconds. Why is real-time voice carried over UDP rather than TCP?
A lost voice packet is useless by the time TCP would retransmit it, and waiting for it would stall every packet behind it (head-of-line blocking). Dropping the late packet and playing on gives a brief glitch instead of a long freeze. Voice usually rides RTP over UDP.
5. A packet capture shows many "TCP Retransmission" and "Dup ACK" lines on a file transfer. What does this indicate?
Packets are being lost or badly delayed on the path. Duplicate ACKs mean the receiver keeps acknowledging the last in-order byte because a later segment arrived but an earlier one is missing; the sender then retransmits. Investigate congestion, a failing link, duplex mismatch or a faulty interface, not the application.
6. A secondary DNS server cannot copy a zone from the primary. Which port must the firewall allow?
TCP 53. Zone transfers (AXFR and IXFR) use TCP because the data is large and needs reliable delivery. Allowing only UDP 53 is the classic mistake.
7. An engineer is told to back up a router configuration to a TFTP server. Which port and transport must the firewall allow?
UDP 69 to start the transfer (TFTP then continues the exchange from a negotiated port, which is why firewalls need TFTP awareness). Port 21 is FTP control over TCP, and 22 is SSH over TCP; neither is TFTP.
8. A port scan sends a probe to a closed port. What reply does a closed TCP port give compared with a closed UDP port?
A closed TCP port answers with a RST segment. A closed UDP port normally triggers an ICMP "port unreachable" message from the host. If a UDP probe gets no reply at all, the port is open or filtered, which is why UDP scans are slow and ambiguous.
Frequently asked questions
What is the main difference between TCP and UDP?
TCP is connection-oriented and reliable: it sets up a connection with a three-way handshake, numbers every byte, retransmits lost data, delivers it in order and controls the sending rate. UDP is connectionless and best-effort: it sends independent datagrams with no handshake, no retransmission and no ordering, which makes it lighter and faster but leaves any reliability to the application.
Is UDP faster than TCP?
UDP has less overhead (an 8-byte header against at least 20 bytes for TCP, no handshake, no acknowledgements), so it can deliver the first byte sooner and adds no retransmission delay. That is not the same as higher throughput on a clean link; TCP can saturate a link efficiently. UDP wins when latency matters more than completeness, such as voice, live video, gaming and DNS lookups.
Does DNS use TCP or UDP?
Both. Ordinary DNS queries and responses use UDP port 53 because they are short and one round trip is enough. DNS falls back to TCP port 53 when a response is too large for UDP, and always uses TCP for zone transfers between servers. DNS over TLS and DNS over HTTPS run over TCP-based or QUIC-based transports instead.
Does HTTP/3 use TCP or UDP?
HTTP/3 runs over QUIC, and QUIC runs over UDP, normally on port 443. QUIC builds its own reliability, ordering, congestion control and TLS 1.3 encryption on top of UDP datagrams. HTTP/1.1 and HTTP/2 still run over TCP, so a modern browser may use either depending on what the server supports.
What are the TCP and UDP port number ranges?
Both protocols use 16-bit port numbers, so the range is 0 to 65535. By convention, 0 to 1023 are well-known (system) ports, 1024 to 49151 are registered ports, and 49152 to 65535 are dynamic or ephemeral ports used by clients for the source side of a connection. The IANA service name and port number registry is the authoritative list.
Do Network+ and CCNA expect me to memorize port numbers?
Network+ expects you to recognize the common ports and which transport each uses, in both directions: given a port, name the service, and given a service, name the port and protocol. CCNA expects the TCP versus UDP comparison and a working knowledge of the common ports used in access lists and troubleshooting. A short list of about 20 ports covers almost every question.
Can an application use both TCP and UDP?
Yes. Many services register the same port number for both protocols and choose per message: DNS is the classic case, and SIP signaling can use either. Applications can also pair them, for example using TCP for control and UDP for media, as many voice and video systems do.
Sources and further reading
- RFC 9293: Transmission Control Protocol (TCP)
- RFC 768: User Datagram Protocol (UDP)
- IANA Service Name and Transport Protocol Port Number Registry
- RFC 9000: QUIC, a UDP-Based Multiplexed and Secure Transport
- RFC 9114: HTTP/3
- Wireshark User's Guide
- CompTIA Network+ certification page
- Cisco Learning Network: CCNA 200-301 exam topics
Test yourself on ports and protocols
30 free questions per session on Network+ and CCNA, no signup and no credit card. The full 500-question bank is $11.99 lifetime per certification, or $9.99/month Pro unlocks every CertSharp certification.