TCP vs UDP: When Each Is Used
Learn the difference between connection-oriented TCP and connectionless UDP and their security implications.
TCP vs UDP: When Each Is Used is a free Cyber Security Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cyber Security Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Transport Layer
TCP and UDP are the two main protocols at the transport layer (OSI Layer 4). They define how data is sent between applications on different hosts.
TCP: Transmission Control Protocol
TCP is a connection-oriented protocol. Before data is sent, a connection is established via the three-way handshake. TCP guarantees delivery, ordering, and error checking.
Use cases: HTTP/HTTPS, SSH, SMTP, FTP — any application that needs reliability.
The Three-Way Handshake
TCP connection establishment:
- Client sends SYN (synchronize)
- Server replies with SYN-ACK (synchronize-acknowledge)
- Client sends ACK (acknowledge)
Connection is now established. This handshake is the target of SYN flood attacks.
TCP Features
TCP provides:
- Reliability — retransmits lost packets
- Ordering — reassembles packets in correct sequence
- Flow control — prevents overwhelming the receiver
- Congestion control — adapts to network capacity
UDP: User Datagram Protocol
UDP is a connectionless protocol. It sends datagrams without establishing a connection first. No guaranteed delivery, no ordering, no acknowledgment.
Use cases: DNS, VoIP, video streaming, online gaming, DHCP — applications where speed matters more than perfection.
UDP Features
UDP is fast and lightweight:
- No connection overhead
- No retransmission delays
- Lower latency
- Application must handle reliability if needed (e.g., QUIC over UDP)
TCP vs UDP Comparison
Key differences:
- TCP: reliable, ordered, slower, connection-oriented
- UDP: fast, unreliable, connectionless, lower overhead
QUIC (HTTP/3) uses UDP with custom reliability for modern web performance.
Security Implications of TCP
TCP's handshake creates security exposure:
- SYN flood: attacker sends thousands of SYN packets without completing handshakes, exhausting server resources
- TCP session hijacking: attacker predicts sequence numbers to inject data into an existing session
Security Implications of UDP
UDP's lack of connection state enables:
- UDP amplification DDoS: attacker spoofs victim's IP, sends small requests to open UDP services that send large responses back to victim
- DNS amplification: a single small DNS request can trigger a much larger response
Common Port Numbers
Key ports to know:
- TCP 22 — SSH
- TCP 80 — HTTP
- TCP 443 — HTTPS
- UDP 53 — DNS
- UDP 67/68 — DHCP
- TCP 3306 — MySQL
- TCP 3389 — RDP
Viewing Active Connections
Use ss or netstat to inspect open ports and connections:
ss -tulnp
# -t TCP, -u UDP, -l listening, -n numeric, -p show processQuick Check: TCP vs UDP
A DNS query is sent from your computer to resolve a domain name. Which protocol does it use?
Lesson Recap
TCP provides reliable, ordered delivery using a three-way handshake — ideal for HTTP, SSH, and SMTP. UDP is fast and connectionless — ideal for DNS, VoIP, and streaming. Each has distinct security implications: TCP is vulnerable to SYN floods and session hijacking; UDP enables amplification attacks.
Frequently asked questions
Is the “TCP vs UDP: When Each Is Used” lesson free?
Yes — the full text of “TCP vs UDP: When Each Is Used” is free to read here on the web, and the Cyber Security Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cyber Security Academy course, upgrade to CoddyKit PRO.
What will I learn in “TCP vs UDP: When Each Is Used”?
Learn the difference between connection-oriented TCP and connectionless UDP and their security implications. You practise Cyber Security Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Cyber Security Academy?
No prior experience is required. Cyber Security Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “TCP vs UDP: When Each Is Used” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Cyber Security Academy lesson?
Yes. Every Cyber Security Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- IP Addressing and Subnets
- TCP vs UDP: When Each Is Used
- DNS: How Domains Resolve to IPs
- HTTP and HTTPS Basics