TCP Vs UDP


Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) are two foundational communication protocols within the Internet Protocol (IP) suite. While they both serve the purpose of transporting data across networks, their behaviours, guarantees, and typical use cases diverge significantly. For developers, systems administrators, and DevOps engineers, a solid grasp of the differences between TCP and UDP is crucial for building responsive, resilient, and efficient networked systems.
TCP: Reliable, Ordered and Connection-Oriented
Transmission Control Protocol (TCP) is known as a connection oriented protocol. This means that before any data can be exchanged, TCP requires a formal connection to be established between the sender and the receiver. This process is called the three-way handshake and involves three steps:
SYN: The client sends a synchronisation (SYN) packet to the server.
SYN-ACK: The server responds with a synchronisation-acknowledgement (SYN-ACK).
ACK: The client sends back an acknowledgement (ACK), confirming the connection is open.
Only after this exchange can data transmission begin. This handshake mechanism ensures that both parties are ready and aware of the session, laying the groundwork for reliable and ordered communication.
When you open a web browser and visit a website, your browser uses TCP to communicate with the web server. The full contents of a web page – text, images, CSS files – are broken down into packets and sent to you. Thanks to TCP, these packets arrive in order, intact, and complete, even if they were routed through different paths across the internet. If any packet gets lost in transit, TCP will automatically detect the loss and request a retransmission.
This reliability makes TCP ideal for:
HTTP/HTTPS web traffic
Email protocols like SMTP, IMAP and POP3
File transfers via FTP or SFTP
Remote administration via SSH
TCP also implements flow control and congestion control. Flow control ensures that a fast sender doesn’t overwhelm a slower receiver, while congestion control dynamically adjusts data transmission rates based on network conditions. These features make TCP resilient in high latency or congested networks, though it does add additional overhead.
UDP: Lightweight, Fast and Connectionless
User Datagram Protocol (UDP) is a connectionless protocol. It does not perform a handshake, nor does it wait for acknowledgements from the receiver. It simply fires off packets called datagrams and hopes they reach their destination.
This “fire and forget” approach makes UDP extremely fast, with minimal latency and processing overhead. However, this comes at a cost: there is no guarantee of delivery, order, or duplication control.
Example: Online Gaming and UDP
Take an online multiplayer game. The positions of players and actions like movement or firing a weapon need to be sent to the server and other players as quickly as possible. A slight delay of even 200 milliseconds might ruin the experience. In this context, it’s better to skip a few updates than to wait for lost packets to be resent.
UDP is well suited for:
Real-time applications like online gaming
Live audio or video streaming
Voice over IP (VoIP) calls
DNS lookups
Sensor data feeds in IoT applications
Let’s say you’re in a Zoom call. If a packet containing part of someone’s voice is lost, there’s no time to resend it , it’s more efficient to keep going and perhaps fill the gap with noise reduction or silence, rather than delay the stream and cause jitter.
TCP Overhead vs UDP Efficiency
TCP adds overhead through its connection setup, sequence numbers, acknowledgements, and error handling. For instance, every TCP packet includes a header with around 20 bytes of control information. This is important for tracking order and retransmissions but consumes bandwidth.
UDP, on the other hand, has a much smaller header typically just 8 bytes making it ideal for time sensitive applications that transmit many small packets. This smaller footprint also means fewer CPU cycles spent parsing packet metadata, which can be important on mobile devices or embedded systems.
However, the burden of reliability falls on the application layer when using UDP. For example, a custom video streaming app might implement its own error correction or sequencing system on top of UDP effectively rebuilding some TCP features as needed, but with more control.
Considerations
Port Numbers and Firewalls
Both TCP and UDP use port numbers to identify specific services on a machine. TCP port 80, for instance, is traditionally used for HTTP traffic, while UDP port 53 is reserved for DNS. Firewalls often treat TCP and UDP differently TCP's predictable nature makes it easier to filter or inspect, while UDP can be trickier to monitor due to its stateless design.
Hybrid Use
Some modern protocols use both. For example, QUIC (used in HTTP/3) operates over UDP but builds in many of TCP’s features like connection establishment, encryption, and stream management, offering the best of both worlds.
Understanding the strengths and limitations of TCP and UDP is fundamental to effective system design. In real world deployments, the protocol you choose directly impacts performance, reliability, and user experience. Whether you're building a chat app, a multiplayer game, a secure financial system, or an internal API gateway, choosing the right transport layer protocol can be the difference between a smooth experience and a frustrating one.
As with all engineering decisions, context is king. Don’t default to TCP because it's "safer" or UDP because it’s "faster" understand the trade offs and let your application's goals dictate your protocol.
If you're working on systems that require both low latency streaming and transactional reliability, consider implementing separate channels using each protocol where appropriate a pattern seen in modern media streaming platforms and cloud native architectures. Both protocols have distinct advantages depending on the use case. TCP is typically favoured for applications where accuracy and reliability of data transmission are paramount, such as file transfers, emails, or web browsing, as any lost packets are resent automatically, ensuring complete and ordered data delivery. UDP, on the other hand, excels in scenarios where speed and reduced latency are essential, and slight data loss can be tolerated. This is ideal in situations like online gaming or streaming services, where minor interruptions are less disruptive than delayed data.
In the end, the choice between TCP and UDP hinges on the specific requirements of the application. Understanding their differences allows network engineers and developers to optimise communication protocols effectively, balancing the need for reliability, speed, and performance according to the context of use.
Subscribe to my newsletter
Read articles from Patrick Kearns directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
