4.3.8. TCP vs UDP
Table of Contents
Big Picture Comparison
TCP and UDP are both transport layer protocols that sit above IP. They both use port numbers to deliver data to the right application. The main difference is in how they handle reliability, ordering, and overhead.
TCP is connection oriented and focuses on reliable, ordered delivery. UDP is connectionless and focuses on speed and simplicity, even if some data is lost or arrives out of order.
You will see TCP used when correctness matters more than speed, and UDP when speed and low delay matter more than reliability.
Core Feature Differences
Although both TCP and UDP carry data between applications, they provide very different services.
TCP sets up a connection before data transfer. This uses a handshake so both sides agree on starting sequence numbers and are ready to communicate. Once the connection exists, TCP numbers bytes, keeps track of what has been received, and resends lost data.
UDP sends individual messages called datagrams without creating a formal connection. Each UDP datagram is independent. There is no handshake, and the sender does not track what the receiver got.
The effect is that TCP hides many network problems from the application by fixing them, while UDP exposes those problems to the application, which then decides whether to handle them or ignore them.
Summary Table
| Aspect | TCP | UDP |
|---|---|---|
| Connection model | Connection oriented | Connectionless |
| Reliability | Yes, with retransmissions | No, best effort only |
| Ordering | Guaranteed ordered delivery | No ordering guarantee |
| Congestion control | Yes | No, application must handle if needed |
| Flow control | Yes | No |
| Header size | Larger, more fields | Smaller, fewer fields |
| Speed / latency | Higher overhead, usually slower | Lower overhead, usually faster |
| Typical use cases | Web, email, file transfer, SSH | VoIP, online games, streaming, DNS |
Reliability and Delivery Guarantees
The most important difference is how each protocol treats the data delivery promise.
TCP guarantees that data is delivered reliably and in order, or that the connection fails. It detects lost segments and resends them. It detects duplicates and discards them. It reorders out of order segments before passing data to the application. The application sees a clean byte stream.
UDP makes almost no guarantees. A UDP datagram can be lost, duplicated, or delivered out of order. The network tries to deliver it, but there is no built in correction if something goes wrong. The application receives whatever arrives and must decide what to do.
TCP provides reliable, ordered, and error checked delivery of a byte stream.
UDP provides unreliable, unordered, best effort delivery of individual datagrams.
This difference has a huge impact on application design. Applications that use TCP can be simpler because they rely on the transport layer to correct many errors. Applications that use UDP must either tolerate loss or implement their own reliability logic.
Connection Oriented vs Connectionless
With TCP, a connection is a logical relationship between two endpoints identified by IP addresses and port numbers. The connection has state. Both ends store information about sequence numbers, acknowledgments, and window sizes. This state must be created and later removed.
With UDP, there is no connection state in the protocol itself. The sender just builds a UDP datagram with a source port, destination port, and data, then sends it. The receiver does not need to agree in advance. It simply listens on a port and processes whatever arrives.
From an application viewpoint, a TCP connection often looks like a virtual pipe. Data is pushed in at one end and comes out in the same order at the other end. A UDP interaction is more like mailing individual postcards. Each postcard stands alone, and there is no continuous pipe.
Header Structure and Overhead
TCP and UDP wrap application data differently. Both sit on top of IP, but their headers contain different information.
A simple way to compare is by looking at minimum header sizes.
| Protocol | Typical header size (without options) |
|---|---|
| TCP | 20 bytes |
| UDP | 8 bytes |
UDP has a very small header. It includes source port, destination port, length, and checksum. There are no fields for sequence numbers, acknowledgments, or window sizes.
TCP has more fields because it supports reliability, ordering, and control. It includes source and destination ports, sequence number, acknowledgment number, flags, window size, and more. Options can increase the header size beyond the minimum.
UDP header minimum size: 8 bytes.
TCP header minimum size: 20 bytes.
The larger TCP header increases overhead. For very small messages, this overhead can be significant, especially in applications that send many small packets. UDP keeps overhead low, which can be important for latency sensitive data.
Performance, Latency, and Bandwidth Use
TCP spends extra time and bandwidth to provide reliability and fair use of the network. This improves correctness but can increase delay.
TCP needs a handshake before sending data, which adds at least one round trip time before useful data can flow. TCP also waits for acknowledgments and adapts its sending rate based on network congestion. When packets are lost, TCP resends them and may slow down.
UDP starts sending data immediately, with no handshake. Because it does not track state or wait for acknowledgments, it can achieve lower one way delay. There is no automatic slowdown if the network is overloaded, so the application must be careful not to send more than the network can handle.
For bulk file transfer, the extra delay of TCP is usually acceptable because the main goal is correct delivery. For real time audio or video, missing a packet can be better than waiting to resend it, so many such applications prefer UDP.
It is common for applications to limit their own rate when using UDP, to avoid overwhelming the network and causing loss.
Typical Use Cases and Application Choices
Different types of applications choose TCP or UDP based on what they need most.
TCP is used when accuracy, ordering, and completeness are important. Examples include web browsing, email, remote administration, and file transfers. If an HTTP response arrives with missing data, the page might be broken, so reliability is critical. SSH must not lose characters from commands, and file transfers must deliver exact copies.
UDP is used when timeliness and low overhead matter more than perfect delivery. Examples include live audio and video, online gaming, and voice over IP. Losing a single voice packet is usually better than pausing the call to retransmit. Games often care more about the latest position than about old positions arriving late.
Some protocols like DNS use UDP because queries and responses are small and simple. If a DNS response is lost, the client can just try again. In some cases, DNS can also use TCP when responses are too large or when reliability is more important.
Trade Offs and Design Decisions
Choosing between TCP and UDP is about trade offs. No protocol is universally better. The right choice depends on what the application values most.
If an application needs certainty that every byte arrives and arrives in order, and it can accept some extra delay and overhead, TCP is usually the right choice. If an application values speed and can tolerate some loss, and it is willing to handle reliability or accept errors itself, UDP is a better fit.
Some modern applications use UDP and then build their own custom reliability and congestion control on top. This gives them more control over behavior than standard TCP, but also increases complexity.
The key idea is that TCP hides many network issues and provides a simple ordered stream, at the cost of delay and overhead. UDP removes most of that support, giving the application more responsibility, but enabling very low latency and flexible behavior.
Views: 0
Where to Move
Move chapter:
- ☰ 1. Introduction to Networking
- ☰ 1.1. What is a Computer Network?
- ☰ 1.2. Why Networks Matter
- ☰ 1.3. Types of Networks
- ☰ 1.3.1. PAN
- ☰ 1.3.2. LAN
- ☰ 1.3.3. MAN
- ☰ 1.3.4. WAN
-
- ☰ 1.4. Network Topologies
- ☰ 1.4.1. Bus
- ☰ 1.4.2. Star
- ☰ 1.4.3. Ring
- ☰ 1.4.4. Mesh
-
- ☰ 1.5. Network Components
- ☰ 1.5.1. Hosts
- ☰ 1.5.2. Clients / Servers
- ☰ 1.5.3. NICs
- ☰ 1.5.4. Switches
- ☰ 1.5.5. Routers
- ☰ 1.5.6. Modems
-
- ☰ 1.6. Bandwidth, Latency, Throughput
-
- ☰ 2. Binary and Networking Fundamentals
- ☰ 2.1. Binary Numbers
- ☰ 2.2. Bits vs Bytes
- ☰ 2.3. Decimal ↔ Binary Conversion
- ☰ 2.4. Hexadecimal Basics
- ☰ 2.5. Data Units (Kbps, Mbps, Gbps)
- ☰ 2.6. Encapsulation
-
- ☰ 3. OSI Model
- ☰ 3.1. Why Layering?
- ☰ 3.2. Overview of 7 Layers
- ☰ 3.3. Physical Layer
- ☰ 3.4. Data Link Layer
- ☰ 3.5. Network Layer
- ☰ 3.6. Transport Layer
- ☰ 3.7. Session Layer
- ☰ 3.8. Presentation Layer
- ☰ 3.9. Application Layer
- ☰ 3.10. Encapsulation & Decapsulation
- ☰ 3.11. Packet Journey
-
- ☰ 4. TCP/IP Model
- ☰ 4.1. TCP/IP vs OSI
- ☰ 4.2. Internet Layer
- ☰ 4.3. Transport Layer
- ☰ 4.3.1. Ports & Sockets
- ☰ 4.3.2. TCP Overview
- ☰ 4.3.3. Three-Way Handshake
- ☰ 4.3.4. Reliable Transmission
- ☰ 4.3.5. Flow Control
- ☰ 4.3.6. Congestion Control
- ☰ 4.3.7. UDP
- ☰ 4.3.8. TCP vs UDP
-
- ☰ 4.4. Application Layer
- ☰ 4.5. Packet Flow
-
- ☰ 5. Physical Layer & Transmission Media
- ☰ 5.1. Electrical Signals
- ☰ 5.2. Copper Cables
- ☰ 5.2.1. Twisted Pair
- ☰ 5.2.2. Coaxial
-
- ☰ 5.3. Fiber Optics
- ☰ 5.4. Wireless Transmission
- ☰ 5.5. Duplex Modes
- ☰ 5.6. Signal Loss
- ☰ 5.7. Error Detection
-
- ☰ 6. Ethernet and Switching
- ☰ 6.1. Ethernet Basics
- ☰ 6.2. MAC Addresses
- ☰ 6.3. Ethernet Frames
- ☰ 6.4. Collision Domains
- ☰ 6.5. Broadcast Domains
- ☰ 6.6. Hubs vs Switches
- ☰ 6.7. MAC Learning
- ☰ 6.8. VLANs
- ☰ 6.9. Trunking (802.1Q)
- ☰ 6.10. Spanning Tree Protocol
-
- ☰ 7. IP Addressing
- ☰ 7.1. IPv4 Fundamentals
- ☰ 7.2. Public vs Private IP
- ☰ 7.3. Classful Addressing
- ☰ 7.4. Subnet Masks
- ☰ 7.5. CIDR
- ☰ 7.6. Subnetting
- ☰ 7.7. VLSM
- ☰ 7.8. Supernetting
- ☰ 7.9. IP Planning
-
- ☰ 8. IPv6
- ☰ 8.1. Why IPv6?
- ☰ 8.2. IPv6 Address Format
- ☰ 8.3. Address Types
- ☰ 8.4. IPv6 Header
- ☰ 8.5. SLAAC
- ☰ 8.6. Neighbor Discovery
- ☰ 8.7. IPv4 vs IPv6
-
- ☰ 9. Routing Fundamentals
- ☰ 9.1. What is Routing?
- ☰ 9.2. Static Routing
- ☰ 9.3. Dynamic Routing
- ☰ 9.4. Routing Tables
- ☰ 9.5. Administrative Distance
- ☰ 9.6. Metrics
- ☰ 9.7. Default Routes
- ☰ 9.8. Route Summarization
-
- ☰ 10. Routing Protocols
- ☰ 10.1. Distance Vector Routing
- ☰ 10.2. Link State Routing
- ☰ 10.3. RIP
- ☰ 10.4. OSPF
- ☰ 10.5. EIGRP
- ☰ 10.6. BGP
- ☰ 10.7. Path Selection
- ☰ 10.8. Convergence
-
- ☰ 11. ARP, ICMP, and Core Protocols
- ☰ 11.1. ARP
- ☰ 11.2. Gratuitous ARP
- ☰ 11.3. ICMP
- ☰ 11.4. Ping
- ☰ 11.5. Traceroute
- ☰ 11.6. MTU & Fragmentation
-
- ☰ 12. DNS and Name Resolution
- ☰ 12.1. Why DNS?
- ☰ 12.2. Domain Hierarchy
- ☰ 12.3. Recursive Queries
- ☰ 12.4. DNS Record Types
- ☰ 12.4.1. A
- ☰ 12.4.2. AAAA
- ☰ 12.4.3. CNAME
- ☰ 12.4.4. MX
- ☰ 12.4.5. TXT
-
- ☰ 12.5. DNS Caching
- ☰ 12.6. DNS Security
-
- ☰ 13. Application Layer Protocols
- ☰ 13.1. HTTP / HTTPS
- ☰ 13.2. FTP / SFTP
- ☰ 13.3. SMTP
- ☰ 13.4. POP3
- ☰ 13.5. IMAP
- ☰ 13.6. SSH
- ☰ 13.7. Telnet
- ☰ 13.8. DHCP
- ☰ 13.9. SNMP
- ☰ 13.10. NTP
-
- ☰ 14. Wireless Networking
- ☰ 14.1. Radio Fundamentals
- ☰ 14.2. Wi-Fi Standards
- ☰ 14.3. Frequency Bands
- ☰ 14.4. Channels
- ☰ 14.5. Roaming
- ☰ 14.6. Interference
- ☰ 14.7. WPA2 / WPA3
- ☰ 14.8. Enterprise Wi-Fi
-
- ☰ 15. NAT and Internet Connectivity
- ☰ 15.1. NAT Basics
- ☰ 15.2. PAT
- ☰ 15.3. Port Forwarding
- ☰ 15.4. ISP Concepts
- ☰ 15.5. CGNAT
- ☰ 15.6. Internet Routing
-
- ☰ 16. Network Security Fundamentals
- ☰ 16.1. CIA Triad
- ☰ 16.2. Firewalls
- ☰ 16.3. ACLs
- ☰ 16.4. VPN
- ☰ 16.5. IDS / IPS
- ☰ 16.6. Zero Trust
- ☰ 16.7. DDoS
- ☰ 16.8. Malware in Networks
- ☰ 16.9. Security Hardening
-
- ☰ 17. Network Services
- ☰ 17.1. Load Balancing
- ☰ 17.2. Reverse Proxy
- ☰ 17.3. Web Hosting
- ☰ 17.4. CDN
- ☰ 17.5. DNS Hosting
-
- ☰ 18. Monitoring and Troubleshooting
- ☰ 18.1. Troubleshooting Methodology
- ☰ 18.2. Layer-by-Layer Debugging
- ☰ 18.3. Ping / Traceroute
- ☰ 18.4. Netstat
- ☰ 18.5. Tcpdump
- ☰ 18.6. Wireshark
- ☰ 18.7. Logs
- ☰ 18.8. Packet Analysis
-
- ☰ 19. Virtualization and Cloud Networking
- ☰ 19.1. Virtual Switches
- ☰ 19.2. Hypervisors
- ☰ 19.3. SDN
- ☰ 19.4. Overlay Networks
- ☰ 19.5. Containers & Networking
- ☰ 19.6. Kubernetes Networking
- ☰ 19.7. Cloud VPCs
-
- ☰ 20. Advanced Enterprise Networking
- ☰ 20.1. MPLS
- ☰ 20.2. VXLAN
- ☰ 20.3. EVPN
- ☰ 20.4. SD-WAN
- ☰ 20.5. QoS
- ☰ 20.6. Traffic Engineering
-
- ☰ 21. Automation & Infrastructure as Code
- ☰ 21.1. Why Automation?
- ☰ 21.2. APIs
- ☰ 21.3. REST
- ☰ 21.4. Python for Networking
- ☰ 21.5. Netmiko
- ☰ 21.6. Ansible
- ☰ 21.7. Terraform
- ☰ 21.8. Configuration Management
-
- ☰ 22. Network Design
- ☰ 22.1. Small Office Design
- ☰ 22.2. Enterprise Design
- ☰ 22.3. Data Center Networks
- ☰ 22.4. Redundancy
- ☰ 22.5. High Availability
- ☰ 22.6. Capacity Planning
-
- ☰ 23. Specialized Topics
- ☰ 23.1. IoT Networking
- ☰ 23.2. Industrial Networks
- ☰ 23.3. 5G Basics
- ☰ 23.4. Satellite Networks
- ☰ 23.5. HPC Networking (InfiniBand, RDMA)
- ☰ 23.6. Edge Computing
-
- ☰ 24. Capstone Projects
- ☰ 24.1. Home Lab Project
- ☰ 24.2. Enterprise Network Design
- ☰ 24.3. Secure Multi-Site Network
- ☰ 24.4. Packet Analysis Project
- ☰ 24.5. Cloud Networking Project
-
- ☰ 25. Bonus Content
- ☰ 25.1. Certification Prep (CCNA / CCNP)
- ☰ 25.2. Interview Questions
- ☰ 25.3. Hands-on Labs
- ☰ 25.4. Real-World Case Studies
- ☰ 25.5. Final Exam
-
Comments
Please login to add a comment.
Don't have an account? Register now!