6.02 Compare and contrast Transmission Control Protocol (TCP) and User Datagram Protocol (UDP)
Introduction
As we've discussed before, digital information is broken down into bits (1's and 0's) and then converted into a physical medium (such as electrical signals, light pulses, or radio waves) to be transmitted across networks. This process is somewhat like Morse code, where a series of signals is used to convey meaning.
If you only had two types of signals (like 1's and 0's), how would you communicate complex concepts or large amounts of information with someone on the other end? You would need a common understanding or set of rules for how the information should be interpreted. This is where protocols in networking come into play.
Protocols are pre-established rules that dictate how communication is handled, depending on the type of data being transmitted or how it needs to be sent. These protocols ensure that devices on a network can interpret and manage the data consistently and efficiently.
This concept is essential to ensure that large amounts of information or complex messages are communicated accurately, regardless of the type of physical medium being used.
Protocols and Ports
Network hardware and protocols we've covered so far focus on moving frames and packets between hosts and networks.
Here's a breakdown of how different layers handle communication:
Link Layer: Ethernet is used to send frames of data between hosts using MAC addresses.
Internet Layer: IP (Internet Protocol) provides addressing and routing for connecting different networks.
Next, we move to the Transport Layer of the TCP/IP protocol stack.
Transport Layer and Port Numbers
The Transport Layer is responsible for identifying and managing multiple types of network data being sent and received by a host. This layer uses port numbers to do this, allowing the host to know which application the data belongs to.
Port numbers range from 0 to 65535.
For example:
Port 80 is used for HTTP (web browsing).
Port 25 is used for email services.
A host can be sending or receiving different types of data (like web and email) at the same time. Port numbers make it possible to handle multiple data streams through the same network connection by multiplexing them.
How Port Numbers Work
Each host assigns two port numbers during communication:
Destination Port Number: This identifies the service being requested.
Example: If a client requests a webpage, it sends data to port 80 (for HTTP).
2. Source Port Number: This is randomly assigned by the client and used by the server to track the conversation.
Example: The client assigns a random source port, such as 47747. The server replies to this port.
This system allows hosts to manage multiple conversations for the same application without confusion.
TCP and UDP: Transport Layer Protocols
In the TCP/IP suite, two main protocols manage port assignments:
TCP (Transmission Control Protocol): Ensures reliable, ordered data transmission.
UDP (User Datagram Protocol): Offers faster, but less reliable, data transmission.
In summary, the Transport Layer uses port numbers to manage communication between hosts, allowing multiple applications to operate on the same network connection. TCP and UDP are the two main protocols used for handling these port assignments.
TCP vs. UDP
Transmission Control Protocol (TCP)
IP transmits application data as packets, but these packets can be lost or damaged due to network issues. Transmission Control Protocol (TCP) is a connection-oriented protocol that adds reliability by ensuring data is transmitted correctly.
Here’s how TCP works:
Key Functions of TCP
Connection Establishment:
TCP uses a handshake sequence to establish a reliable connection:
SYN (synchronize): The sender requests to start communication.
SYN/ACK (synchronize/acknowledge): The receiver acknowledges the request.
ACK (acknowledge): The sender confirms the connection.
Packet Tracking: TCP assigns a sequence number to each packet, allowing the receiver to keep track of the order and detect missing packets.
Acknowledgement (ACK): The receiver sends an ACK to confirm that a packet was successfully received.
Negative Acknowledgement (NACK): If a packet is missing or damaged, the receiver can send a NACK to request that the sender retransmit the data.
Graceful Termination: TCP ensures a smooth end to a communication session using a FIN handshake, where both parties agree to terminate the connection.

Overhead of TCP
Header Size: TCP adds reliability but at the cost of increased data overhead. Each TCP packet includes 20 bytes or more of extra information in the header to manage the connection, sequence, and acknowledgments.
When is TCP Used?
TCP is used when data integrity is critical and missing or damaged information cannot be tolerated.
Here are examples of protocols that rely on TCP:
HTTP/HTTPS (HyperText Transfer Protocol / Secure): Used for delivering web pages and other resources. HTTPS adds encryption for security. A single missing packet can cause the entire webpage load to fail.
SSH (Secure Shell): Used to access the command-line interface of a computer over a network. SSH encrypts data for secure communication. Missing packets would cause the session to fail.
In summary, TCP ensures that data is reliably transmitted by using connection-oriented mechanisms like the three-way handshake, packet tracking, acknowledgments, and retransmissions. This makes TCP essential for applications that require accurate and complete data transmission.
User Datagram Protocol (UDP)
User Datagram Protocol (UDP) is a connectionless and non-guaranteed method of communication. Unlike TCP, it does not add extra mechanisms for reliability, such as sequencing or acknowledgments. This means that UDP doesn’t guarantee:
Delivery of packets
Order of packet arrival
Because UDP skips these reliability checks, it has much lower overhead, allowing data to be sent faster than with TCP.
Key Characteristics of UDP
No Handshake or Connection: UDP doesn’t establish a connection before sending data, making it connectionless.
No Acknowledgements: There are no confirmations that the receiver has successfully received the data.
No Packet Sequencing: UDP does not track or guarantee the order in which packets are delivered.
Use Cases for UDP
UDP is used when speed is more important than reliability. It's ideal for applications where occasional missing or out-of-order packets are acceptable. Examples include:
Voice and Video Streaming: UDP is commonly used for real-time applications, such as voice over IP (VoIP) or video streaming. If some data packets are lost, they result in minor glitches, but the connection remains active without significant delay.
Analogy: If you have ever experienced a ‘fuzzy’ video feed from a video-streaming service you may have experienced this UDP connection quality issue. UDP is connectionless, unlike TCP, UDP doesn’t establish a stable connection before transmitting data. It sends data packets without checking whether they arrive or in what order. If packets are lost or arrive out of order, the video can get pixelated or ‘fuzzy’ because the missing data leads to visual glitches.
In TCP, if packets are lost, the protocol asks for them to be retransmitted, ensuring accuracy. However, UDP doesn’t do this. It’s designed for speed and efficiency, which is great for real-time data like live streaming or gaming, but it means there’s no built-in mechanism to fix errors or retransmit lost packets.
Since UDP doesn’t retransmit lost packets, if there’s congestion on your network or poor connection quality, it can lead to frequent packet loss, which results in lower resolution or buffering issues.
Examples of Protocols That Use UDP
Dynamic Host Configuration Protocol (DHCP):
Purpose: DHCP assigns IP addresses to devices on a network.
Why UDP?: DHCP uses broadcast transmissions to request and deliver configuration information. Since TCP does not support broadcasting, DHCP must use UDP. If a DHCP response isn’t received, the client simply retries the process.
Trivial File Transfer Protocol (TFTP):
Purpose: TFTP is used by devices to download configuration files.
Why UDP?: TFTP has its own acknowledgment mechanisms built into the protocol, so it does not need the reliability features of TCP.
Advantages of UDP
Faster Delivery: UDP’s lower overhead makes it faster for applications that require quick data transmission, such as real-time video or audio streaming.
Lightweight: With fewer header bytes and no handshaking, UDP is more efficient for applications that can tolerate occasional data loss.
In summary, UDP is a simpler, faster protocol compared to TCP. It’s best suited for time-sensitive applications where speed is critical, and the occasional loss of packets won't significantly affect performance.
Summary
You're doing a great job! In this section, you’ve learned how protocols and ports manage the flow of data across networks. You now understand how TCP provides reliable, ordered communication through its connection-oriented process, ensuring data reaches its destination correctly—essential for applications like web browsing and secure communication. On the other hand, UDP offers a faster, more lightweight alternative, best for real-time applications like streaming or gaming, where occasional data loss is acceptable. By grasping the balance between speed and reliability in TCP and UDP, you're well-equipped to understand how different types of network traffic are handled! Keep it up—you're building a strong foundation in networking!