← Back to OSI Overview

Layer 4: Transport Layer

Reliable End-to-End Communication

The Transport Layer provides reliable data transfer services to the upper layers. It handles error detection, error recovery, flow control, and ensures complete data transfer between host systems.

Layer 4 (Transport) Technologies

The Transport Layer is responsible for reliable end-to-end data delivery between applications. It provides connection management, error recovery, flow control, and data segmentation between processes running on different hosts.

Connection Management - Establishing, maintaining, and terminating connections between applications
Reliable Delivery - Ensuring all data arrives correctly and in order (TCP) or fast delivery (UDP)
Flow Control - Managing data transmission rate to prevent buffer overflow
Port-based Multiplexing - Multiple applications sharing the same network connection

The Critical Role: While Layer 3 routes packets between networks, Layer 4 ensures reliable communication between specific applications using port numbers and connection state management.

📱

Client App

Port 12345
Ready
Connect
Transfer
Acknowledge
TCP
TCP
Transport Status:
Select a protocol and mode to begin
Step 0 of 0
Connection Idle
📡

Server App

Port 80
Listening

Transport Protocol Information

Choose a protocol above to see how it manages the conversation.

🎯 Primary Functions

  • Segmentation: Breaking data into smaller, manageable segments
  • Error Detection & Recovery: Ensuring data integrity
  • Flow Control: Managing data transmission rates
  • Connection Management: Establishing and terminating connections
  • Multiplexing: Multiple applications using the network simultaneously

🔧 Key Characteristics

  • Port Numbers: Identify specific applications (0-65535)
  • Sequence Numbers: Track data order and completeness
  • Acknowledgements: Confirm successful data receipt
  • Window Size: Control flow and prevent buffer overflow
  • Checksums: Detect transmission errors

🌐 Major Transport Layer Protocols

🔒 TCP (Transmission Control Protocol)

Connection-oriented, Reliable

TCP [SYN] Seq=0 Win=65535 Len=0 TCP [SYN, ACK] Seq=0 Ack=1 Win=65535 TCP [ACK] Seq=1 Ack=1 Win=65535

What you see in Wireshark: Three-way handshake with SYN, SYN-ACK, ACK flags

Like a phone call - establish connection, talk, hang up properly

📡 UDP (User Datagram Protocol)

Connectionless, Fast

UDP Src Port: 53 (dns) UDP Dst Port: 54321 Length: 45 bytes Checksum: 0x1a2b [correct]

What you see in Wireshark: Simple header with source/dest ports, length, and checksum

Like sending a postcard - quick, simple, no delivery guarantee

🔄 SCTP (Stream Control Transmission)

Multi-streaming, Reliable

SCTP INIT Chunk Verification Tag: 0x00000000 Multiple streams supported

What you see in Wireshark: Chunk-based protocol with multi-homing support

Like TCP but with multiple lanes on the highway

🏢 SPX (Sequenced Packet Exchange)

NetWare's reliable protocol

SPX: Connection Control: 0x40 SPX: Sequence Number: 1234 SPX: Acknowledge Number: 5678

What you see in Wireshark: Similar to TCP but for Novell networks

Legacy protocol mostly replaced by TCP

⚖️ TCP vs UDP Comparison

Feature TCP UDP
Connection Connection-oriented
(3-way handshake)
Connectionless
(fire and forget)
Reliability Guaranteed delivery
Error recovery
Best effort
No error recovery
Speed Slower
(overhead for reliability)
Faster
(minimal overhead)
Header Size 20 bytes minimum 8 bytes fixed
Flow Control Yes (sliding window) No
Use Cases Web browsing, Email
File transfer, Databases
DNS queries, Video streaming
Online gaming, DHCP

🔍 Real-World Example: Web Page Download (TCP)

Scenario: Your browser downloads a webpage from a server

What happens at the Transport Layer:

  1. Connection Establishment: Browser initiates TCP 3-way handshake with server
  2. Data Segmentation: Large webpage is broken into TCP segments
  3. Reliable Delivery: Each segment is numbered and acknowledged
  4. Error Handling: Missing segments are automatically retransmitted
  5. Flow Control: Prevents server from overwhelming browser
  6. Connection Termination: 4-way handshake to close connection
Wireshark Transport Layer Analysis: TCP: [SYN] Seq=0 Win=65535 Len=0 MSS=1460 TCP: [SYN,ACK] Seq=0 Ack=1 Win=65535 Len=0 TCP: [ACK] Seq=1 Ack=1 Win=65535 Len=0 TCP: HTTP request data [PSH,ACK] Seq=1 Len=500 TCP: HTTP response data [PSH,ACK] Seq=1 Len=1460 TCP: [ACK] Seq=501 Ack=1461 (acknowledging data)

In Wireshark, you can see the complete TCP conversation with all control flags and sequence numbers.

🎮 Understanding Port Numbers

Port numbers allow multiple applications to use the network simultaneously. Think of them as apartment numbers in a building (IP address).

Well-Known Ports (0-1023)

Port 80
HTTP
Port 443
HTTPS
Port 25
SMTP
Port 53
DNS
Port 21
FTP
Port 22
SSH

Ephemeral Ports

IANA reserves 49152–65535 as the dynamic/private range, but operating systems choose their own: Linux defaults to 32768–60999, Windows to 49152–65535. Ports 1024–49151 in between are the registered range (MySQL 3306, RDP 3389, and so on).

Port 54321
Browser
Port 49152
Email Client
Port 60000
Game Client
Port 55555
Chat App
Example Connection: Client 192.168.1.100:54321 → Server 192.168.1.50:80 (Your computer's random port → Web server's HTTP port)

🐛 Common Transport Layer Issues

  • Port Conflicts: Multiple applications trying to use same port
  • Firewall Blocking: Ports blocked by security policies
  • Connection Timeouts: Network congestion or server overload
  • Packet Loss: Network issues causing retransmissions
  • Buffer Overflow: Receiving data faster than processing

🔧 Troubleshooting Tools

  • Netstat: Show active connections and listening ports
  • Wireshark: Analyse packet flow and connection states
  • Telnet: Test if specific ports are accessible
  • TCPView: Real-time view of TCP and UDP activity
  • SS/Netstat: Socket statistics and connection info

🎓 Teaching Analogy: Shipping and Postal Services

Think of the Transport Layer like different shipping services:

🔒 TCP = Certified Mail with Tracking

📡 UDP = Regular Mail

The Transport Layer chooses the right "shipping method" based on what the application needs!

📚 Key Learning Points

Check your understanding — Layer 4

Five questions on Layer 4 — TCP, UDP, ports and reliability.

  1. What is the PDU at the Transport Layer?

  2. In what order does the TCP three-way handshake happen?

  3. Which transport protocol is connectionless?

  4. What is the minimum size of a TCP header?

  5. HTTP/3 runs on top of which transport?

Layer 4 (Transport) — frequently asked questions

What is the Transport Layer?

The Transport Layer is Layer 4. It delivers data between specific applications rather than merely between hosts, using port numbers to tell them apart. Depending on the protocol chosen it may also segment large amounts of data, acknowledge and retransmit what is lost, put segments back in order, and control the sending rate.

TCP or UDP — which should I use?

Use TCP when every byte must arrive, in order: web pages, email, file transfer, databases. Use UDP when late data is worthless and speed matters more than completeness: live voice and video, DNS lookups, DHCP, game state updates. Modern protocols increasingly build their own reliability on UDP — QUIC is the clearest example.

What is a port number?

A port is a 16-bit number (0–65535) that identifies which application on a host a segment belongs to. The IP address gets the data to the right machine; the port gets it to the right process. Well-known ports run 0–1023 (HTTP 80, HTTPS 443, SSH 22), registered ports 1024–49151, and dynamic ports 49152–65535.

Why does closing a TCP connection take four steps?

TCP connections are full-duplex, so each direction has to be closed independently. Each side sends its own FIN and receives an ACK for it — FIN, ACK, FIN, ACK — which lets one side finish sending while the other is still transmitting.

← Return to OSI Overview