In-Depth Guide to the Transport Layer: Understanding TCP and UDP Protocols


This is the sixth part of the computer networking series. Check out the previous parts if you haven’t! In this post, we’ll dive into the Transport Layer and its protocols: TCP and UDP.
Table of Contents
- What Is the Transport Layer?
- How Does the Transport Layer Work?
- Ensuring Data Integrity
- Transport Layer Protocols
- TCP’s 3-Way Handshake
What Is the Transport Layer?
The Transport Layer plays a crucial role in moving data between applications and networks.
Example
Imagine texting your friend on WhatsApp:
- The Network Layer ensures your message reaches your friend’s device.
- The Transport Layer ensures the data moves from the WhatsApp app on your device to the network, and then from the network to WhatsApp on your friend’s device.
How Does the Transport Layer Work?
Data Transmission
- Packets: Data is divided into packets for transmission.
- Multiplexing: The transport layer sends packets to the network using a multiplexer.
- Demultiplexing: It receives packets from the network and sends them to the correct application.
- Port Numbers: The transport layer attaches port numbers to packets for identification.
Congestion Control
The transport layer monitors network traffic to prevent congestion.
Ensuring Data Integrity
Checksums
Checksums help detect corruption during data transfer.
- The sender calculates a checksum using an algorithm and sends it along with the data.
- The receiver calculates a checksum for the received data.
- If the checksums match, the data is intact. If not, the data is corrupted.
Timers
Timers ensure data delivery:
- When a packet is sent, a timer starts.
- If no acknowledgment (ACK) is received before the timer expires, the sender knows the data didn’t arrive and resends it.
- Sequence Numbers: Prevent duplicate packets from causing confusion.
Transport Layer Protocols
The Transport Layer has two main protocols:
1. User Datagram Protocol (UDP)
- Unreliable: Data may or may not be delivered.
- Connectionless: It doesn’t establish a connection before sending data.
- Error Handling: UDP uses checksums but doesn’t handle errors—it simply discards corrupted packets.
- Speed: It’s faster because it doesn’t check for delivery or errors.
Applications of UDP
- Video conferencing (e.g., Zoom, Teams)
- DNS (Domain Name System)
- Online gaming
2. Transmission Control Protocol (TCP)
- Reliable: Ensures data is delivered without errors.
- Connection-Oriented: Data is sent only after a connection is established.
- Order Preservation: Ensures packets arrive in the correct order.
- Error and Congestion Control: Checks for errors and manages network congestion.
- Full Duplex: Data can be sent and received simultaneously.
How TCP Works
- Segmentation:
- TCP divides large chunks of data into smaller segments, adding headers and checksums.
- At the receiver’s end, it reassembles segments into the original data.
- Features:
- Error control
- Congestion control
- Sequence numbers to maintain order
TCP’s 3-Way Handshake
The 3-way handshake is a process to establish a TCP connection.
SYN: The client sends a connection request with:
- A synchronization (SYN) flag
- A random sequence number for security
SYN-ACK: The server responds with:
- A SYN flag
- An acknowledgment (ACK) flag
- A new sequence number and an acknowledgment number (client's sequence number + 1)
ACK: The client sends:
- An ACK flag
- Its updated sequence and acknowledgment numbers
Once this process is complete, a reliable connection is established.
This wraps up the Transport Layer and its protocols. Stay tuned for the next part, where we’ll dive deeper into more networking concepts!
Subscribe to my newsletter
Read articles from Vignesh J directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Vignesh J
Vignesh J
I am Vignesh. I build full-stack web applications using the MERN stack and Java full-stack. I am a technical writer who writes technical content on dev.to and Medium. I have around 5k followers on dev.to. I contribute to open-source projects and have also maintained an open-source project of my own. I have participated in a few open-source programs, both as a contributor and a maintainer: -> Secured 3rd place as a contributor among 100+ participants in Code Sapiens 2024. -> Secured 7th place as a Contributor team among 1650+ teams in DevFest AI 2024. -> Secured 14th place as a project admin among 415+ projects in GirlScript Summer of Code 2024 - Extd. -> Completed the 4 PR mark as a contributor in Hacktoberfest 2024. -> Participated as a maintainer in Hacktoberfest 2024. I am passionate about building impactful software solutions and fostering collaboration in the open-source community. I enjoy working in collaborative environments and mentoring contributors in open-source communities. Feel free to connect with me to discuss web development, open-source contributions, or technical writing. I'm always happy to collaborate and share ideas!