What is the Transport Layer?
The Transport Layer is Layer 4 in the OSI model and acts as a manager that ensures data gets from one program on your computer to the right program on another computer.
- Deliver data to the correct application using port numbers
- Ensure reliable or fast delivery (TCP vs UDP)
- Manage data flow and network congestion
TCP vs UDP Comparison
Feature | TCP (Transmission Control Protocol) | UDP (User Datagram Protocol) |
---|---|---|
Reliability | ✅ Reliable - Resends lost data | ❌ Unreliable - No resending |
Speed | 🐢 Slower due to error checking | 🚀 Faster with minimal overhead |
Connection | 🔗 Connection-oriented | 📡 Connectionless |
Data Order | ✅ Maintains order | ❌ No order guarantee |
Use Cases | Web browsing, emails, file transfers | Video streaming, gaming, live calls |
TCP (Transmission Control Protocol)
TCP is the reliable choice for data transmission, ensuring every piece of data arrives safely and in order.
- Reliable: Automatically detects and retransmits lost data
- Ordered: Data arrives in the same sequence it was sent
- Connection-oriented: Establishes connection before data transfer
- Error-checking: Validates data integrity
UDP (User Datagram Protocol)
UDP prioritizes speed over reliability, making it perfect for real-time applications where occasional data loss is acceptable.
- Fast: Minimal processing overhead
- Lightweight: Small header size
- Connectionless: No setup required
- No guarantees: Best-effort delivery
TCP Header & Flags
TCP flags are control signals in the TCP header that manage connection states and data flow.

3-Way Handshake
The 3-Way Handshake is TCP's method to establish a reliable connection before data transmission begins.

"Hello server, I want to connect!" (SYN flag set)
"Hi client, I'm ready! Let's connect!" (SYN + ACK flags set)
"Great! Connection established!" (ACK flag set)
4-Way Termination
The 4-Way Termination is how TCP gracefully closes connections, ensuring both parties agree to end communication.

"I'm done sending data." (FIN flag set)
"Got it, I understand you're done." (ACK flag set)
"I'm also done sending data." (FIN flag set)
"Okay, connection closed!" (ACK flag set)
Flow Control
Flow control prevents the sender from overwhelming the receiver by managing the rate of data transmission.
- Uses a window size to control data flow
- Receiver advertises available buffer space
- Sender adjusts transmission rate accordingly
- Prevents buffer overflow at the receiver
Congestion Control
Congestion control manages network traffic to prevent network overload and ensure optimal performance for all users.
- Slow Start: Gradually increases sending rate
- Congestion Avoidance: Maintains optimal rate
- Fast Recovery: Quickly responds to congestion
- Timeout handling: Reduces rate when packets are lost
Port Numbers
Port numbers help the Transport Layer direct incoming data to the correct application on a device.
- 0-1023: Well-known ports (system services)
- 1024-49151: Registered ports (applications)
- 49152-65535: Dynamic/private ports