Transport Layer Fundamentals

Transport Layer Overview

The transport layer is the fourth layer of the OSI reference model. It is responsible for providing a reliable data transfer service between endpoints.


1. The Core Role of the Transport Layer

End-to-end process communication

End-to-end process communication means that the transport layer establishes communication between specific processes on two hosts, in the same way a phone call reaches a specific person who picks up.

Why Is Process Communication Needed?

The building analogy:

LayerAnalogyNetwork layer
Find the buildingFind the building addressNetwork layer: find the host (IP address)
Find the roomFind the specific room numberTransport layer: find the process (port number)
Find the personFind the specific personApplication layer: find the specific service

A concrete case:

  • Network layer: find your computer (192.168.1.10)
  • Transport layer: find your browser (port 80)
  • Application layer: retrieve the web page (HTTP service)

A more vivid analogy:

The network layer is like a courier finding your home address; the transport layer is like the courier knocking on your door and handing the parcel to you personally.

LayerAnalogyActual content
Application layerHand it to Zhang SanProcess: the browser
Transport layerBuilding 3, Unit 5, Room 602Port: 80
Network layerNo. XX, XX Street, Chaoyang District, BeijingIP address: 202.108.22.5

How Process Communication Is Implemented

The transport layer identifies processes with port numbers:

Sender:

  • Your computer’s IP: 192.168.1.10
  • Browser process port: an ephemeral port (for example 54321)
  • Target server IP: 202.108.22.5
  • Target service port: 80 (the HTTP service)

What the transport layer guarantees: the data travels from port 54321 on 192.168.1.10 to port 80 on 202.108.22.5, completing end-to-end communication.


1.2 Transport Layer Addressing: The World of Port Numbers

Port number

A port number is the 16-bit number (0-65535) that the transport layer uses to identify a process, just as a room number identifies a specific room inside a building.

The Role of Port Numbers

The room number analogy:

Building analogyNetwork analogy
Building addressIP address (host)
Room numberPort number (process)
Room occupantA specific process
Function of the roomType of service

What port numbers do:

  1. Identify a process: tell the data which process it belongs to
  2. Distinguish services: separate different network services (HTTP, FTP, and so on)
  3. Manage connections: distinguish different connections in TCP
  4. Dispatch data: deliver data to the correct application

Classification of Port Numbers

1. Well-known ports: 0-1023

Analogy: the public service zone of a building (reception, lifts, fire escapes).

These ports are allocated centrally by IANA for common services:

PortServiceDescriptionAnalogy
20/21FTPFile transferThe parcel room
22SSHSecure remote loginThe VIP entrance
23TelnetRemote loginThe ordinary entrance
25SMTPSending mailThe mail drop box
53DNSName resolutionThe directory enquiry desk
80HTTPWeb serviceThe information desk
110POP3Receiving mailThe mail collection box
143IMAPMail accessThe reading room
443HTTPSSecure webThe VIP service desk

2. Registered ports: 1024-49151

Analogy: the office zone of a building (the company’s offices).

These ports are allocated to specific applications:

PortServiceDescription
1433MS SQL ServerThe Microsoft database
1521OracleThe Oracle database
3306MySQLThe MySQL database
5432PostgreSQLThe PostgreSQL database
6379RedisThe Redis cache
8080HTTP ProxyThe HTTP proxy service

3. Dynamic ports: 49152-65535

Analogy: the temporary activity rooms of a building (for occasional use).

The operating system allocates these dynamically for temporary client connections:

For example, when you open a browser and visit a site, the operating system assigns the browser a temporary port such as 54321; when the connection closes the port is released and made available to other programs.

Allocation and Management of Port Numbers

How the operating system allocates ports:

Server side:

  • Well-known services use fixed ports (for example HTTP uses 80)
  • The port is bound at start-up
  • The service then waits for client connections

Client side:

  • When a connection is initiated, the operating system allocates a port dynamically
  • It normally comes from the dynamic range (49152-65535)
  • The port is released automatically when the connection ends

Port conflicts:

The problem: two programs both want to use port 80.

The resolution:

  1. The program that starts first takes the port
  2. The program that starts second reports “port already in use”
  3. One of them has to change port or the port holder has to be closed

1.3 Multiplexing and Demultiplexing: The Switching Centre of Data Transmission

Multiplexing

Multiplexing means that several application processes share a single transport layer service, in the same way several people share one telephone to make calls.

Demultiplexing

Demultiplexing means that the transport layer distributes incoming data to the corresponding application process, in the same way a telephone exchange forwards an incoming call to a specific person.

The Process of Multiplexing and Demultiplexing

The telephone exchange analogy:

Multiplexing (several people calling): Zhang San, Li Si, and Wang Wu → the telephone → the line → the exchange (three people share the same telephone while calling).

Demultiplexing (forwarding an incoming call): the exchange → the line → the telephone → Zhang San / Li Si / Wang Wu (the call is forwarded to the person identified by the caller display).

Multiplexing and demultiplexing in the network:

Sender (multiplexing): three applications (browser 54321, mail client 54322, chat client 54323) share the transport layer service and hand everything to the network layer as one stream.

Receiver (demultiplexing): network → network layer → transport layer, which distributes the data to the matching application process according to the port number.

How Multiplexing and Demultiplexing Are Implemented

How the transport layer demultiplexes:

Receiving a packet: IP packet → TCP/UDP segment → extract the port numbers.

The demultiplexing steps:

  1. Check the destination port: 80 (the HTTP service)
  2. Look up the process bound to that port: the web server process
  3. Hand the data to that process
  4. The process handles the data

A concrete example:

Scenario: the server receives several requests.

RequestSource IPSource portDestination portContent
Request 1192.168.1.105432180Web page request
Request 2192.168.1.115432225Mail submission

Demultiplexing: data on port 80 → the web server; data on port 25 → the mail server.


1.4 Error Detection and Reliability: The Quality Guarantee of Data Transmission

Error detection

Error detection is the transport layer’s ability to detect errors introduced while data is in transit, in the same way a courier checks a parcel for damage.

Reliability guarantee

A reliability guarantee is the transport layer’s ability to ensure that data is delivered intact, in order, and without duplication, in the same way a courier guarantees that a parcel arrives undamaged.

The Error Detection Mechanism

Error detection in the transport layer:

Sender:

  1. Segment the data
  2. Add a checksum
  3. Send the segment

Receiver:

  1. Receive the segment
  2. Compute the checksum
  3. Compare it with the sender’s checksum
  4. If they do not match, discard the segment
  5. If they match, accept the segment

What the checksum does:

The courier analogy: the courier inspects the appearance of the parcel (the checksum), refuses a damaged parcel (discarding the data), and accepts an intact one (accepting the data).

The Reliability Mechanism

How TCP guarantees reliability:

  1. Sequence numbers: every byte is numbered, so the order of the data is preserved
  2. Acknowledgements: the receiver confirms receipt and the sender learns that the data has arrived
  3. Retransmission: unacknowledged data is sent again, so nothing is lost
  4. Flow control: the sending rate is controlled so the receiver is not overloaded
  5. Congestion control: network congestion is controlled so the network stays stable

The simplicity of UDP:

UDP offers no reliability guarantee: no sequence numbers, no acknowledgements, no retransmission, no flow control — only basic error detection.


2. The Difference Between the Transport Layer and the Network Layer

2.1 Comparison by Layer Function

AspectNetwork layerTransport layer
Scope of communicationHost to hostProcess to process
AddressingIP addressPort number
ReliabilityNot guaranteed (best effort)Can be guaranteed (TCP)
Flow controlNonePresent (TCP)
Connection modelConnectionless (IP)Connectionless (UDP) / connection-oriented (TCP)
ServesHostsProcesses
AnalogyFinding the buildingFinding the room

2.2 How the Two Layers Relate

The network layer is the foundation, the transport layer is the extension:

Network layer: handles communication between hosts, provides IP addressing and routing, and moves data from one host to another.

Transport layer: builds on the network layer to provide process-to-process communication, adds port-based addressing, and moves data from one process to another.

The building analogy:

Network layer: finds the building address (the IP address) and delivers the letter to the entrance of the building.

Transport layer: finds the specific room number (the port number), delivers the letter to the door of that room, and makes sure the letter arrives intact (reliability).


3. The Two Transport Layer Protocols

3.1 TCP: Reliable Transmission

TCP (Transmission Control Protocol)

TCP is the connection-oriented protocol of the transport layer and provides a reliable, ordered, error-free data transfer service. It works like a phone call: you dial first to establish a connection, the voice stays continuous during the call, and you hang up at the end to release it.

Characteristics of TCP

Connection-oriented:

  • A connection has to be established beforehand (the three-way handshake)
  • Connection state is maintained during the exchange
  • The connection is released at the end (the four-way teardown)

Reliability guarantees:

  • Intact data: errors are detected with a checksum
  • Ordered data: order is preserved with sequence numbers
  • Error-free data: errors are corrected by retransmission
  • No loss: delivery is confirmed with acknowledgements

Flow control:

  • The sliding window mechanism
  • Prevents the sender from going too fast
  • The receiver controls the sending rate

Congestion control:

  • Slow start and congestion avoidance
  • Fast retransmit and fast recovery
  • Prevents network congestion

Where TCP Applies

ScenarioCharacteristicWhy TCP is used
File transferData integrity mattersNot a single byte may be lost
Web browsingA complete page mattersPart of a page may not be lost
Mail transferThe message content mattersThe body of the mail may not be lost
Database synchronisationData accuracy mattersNo error at all is acceptable

3.2 UDP: Fast Transmission

UDP (User Datagram Protocol)

UDP is the connectionless protocol of the transport layer and provides a simple, fast data transfer service without any reliability guarantee. It works like sending a text message: it goes out immediately, without checking that it arrived, and it is fast but may be lost.

Characteristics of UDP

Connectionless:

  • No connection has to be established
  • Data is sent directly
  • No connection state is maintained

Simple and efficient:

  • Small protocol overhead
  • Fast processing
  • Straightforward implementation

No reliability guarantee:

  • Data may be lost
  • Data may arrive out of order
  • Nothing is retransmitted

Good real-time behaviour:

  • Low latency
  • No delay for establishing a connection
  • Suitable for real-time applications

Where UDP Applies

ScenarioCharacteristicWhy UDP is used
Voice callsStrong real-time requirementA few lost packets do not spoil the call
Live videoStrong real-time requirementA few dropped frames do not spoil the viewing
Online gamesStrong real-time requirementSpeed matters more than reliability
DNS lookupsSimple and fastOne request, one response

3.3 TCP vs UDP

FeatureTCPUDP
Connection modelConnection-orientedConnectionless
ReliabilityGuaranteedNot guaranteed
OrderingGuaranteedNot guaranteed
Flow controlPresentAbsent
Congestion controlPresentAbsent
Transmission efficiencyLowerHigher
LatencyHigherLower
OverheadLargeSmall
Typical useFile transfer, web pagesReal-time applications, simple queries

Choosing between them:

When to use TCP:

  • Data integrity matters, loss is unacceptable, the volume is large, and real-time behaviour is not critical.

When to use UDP:

  • Real-time behaviour matters, the volume is small, some loss is acceptable, and reliability is not critical.

4. Worked Examples

Example 1: The Process of Visiting a Website

Let us look at the role of the transport layer when you visit a website.

Scenario: a browser visits www.baidu.com.

  1. Application layer: the browser issues an HTTP request
  2. Transport layer (TCP):
    • Port selection: the client’s (browser) ephemeral port 54321, the server’s (Baidu) HTTP port 80
    • Connection establishment: the three-way handshake
    • Data transfer: the HTTP request is sent
  3. Network layer:
    • IP address: the client 192.168.1.10 → the server 202.108.22.5
    • Routing and forwarding: the packets reach the server hop by hop
  4. The server receives:
    • Network layer: receives the IP packet
    • Transport layer: extracts destination port 80 and hands the data to the web server
    • Application layer: the web server handles the HTTP request
  5. The response returns:
    • Transport layer: server port 80 → client port 54321
    • Network layer: server IP → client IP
    • Application layer: the browser renders the page

Example 2: Several Applications Running at Once

Several network applications run on your computer at the same time. How does the transport layer cope?

Scenario: browsing a site, collecting mail, and sending a chat message all at once.

Multiplexing in the transport layer: the browser (54321), the mail client (54322), and the chat client (54323) all go out through TCP and on to the network layer.

Uniform handling in the network layer: all of the data uses the same IP address (192.168.1.10), and the transport layer separates the applications by port number.

Demultiplexing on receipt: network → network layer → TCP, which dispatches by port: 54321 → the browser, 54322 → the mail client, 54323 → the chat client.

Example 3: The DNS Lookup Process

DNS lookups use the UDP protocol.

Scenario: the browser looks up the IP address of www.baidu.com.

  1. Application layer: the browser needs the domain name resolved
  2. Transport layer (UDP):
    • Client port: 49152 (an ephemeral port)
    • DNS server port: 53
    • The DNS query request is sent as a UDP datagram
  3. Network layer: client IP → DNS server IP
  4. The DNS server:
    • Receives the UDP datagram
    • Looks up the IP for the domain
    • Returns the IP address as a UDP datagram
  5. The client:
    • Receives the UDP response and obtains the IP address: 202.108.22.5
    • The browser uses that IP address to reach the site

Characteristics: UDP is simple and fast, one request produces one response, no connection has to be established, and the response comes back quickly.


Exercises

Exercise 1

What is the difference between the transport layer and the network layer, and how do the two cooperate?

transport layernetwork layeraddressing

Approach

Separate the two layers along three axes: what they address, what they guarantee, and how they hand traffic to each other. Then give one end-to-end example that shows the division of labour.

Steps

  1. Compare the scope of communication: host-to-host against process-to-process.
  2. Compare the addressing mechanism: IP address against port number.
  3. Compare the reliability guarantee: best effort against TCP’s guarantee.
  4. Compare flow control: absent at the network layer, present in TCP.
  5. Explain the cooperation: the network layer finds the host, the transport layer finds the process.
  6. Close with a concrete instance.

Answer

The main differences are:

  1. Scope of communication:

    • Network layer: host to host (finds the IP address)
    • Transport layer: process to process (finds the port number)
  2. Addressing mechanism:

    • Network layer: IP address (32 bits or 128 bits)
    • Transport layer: port number (16 bits)
  3. Reliability:

    • Network layer: not guaranteed, best effort
    • Transport layer: guaranteed by TCP, not by UDP
  4. Flow control:

    • Network layer: none
    • Transport layer: present in TCP

How they cooperate:

The network layer and the transport layer divide the work:

  • The network layer finds the target host (the IP address)
  • The transport layer finds the target process (the port number)

The courier analogy makes the division concrete:

  • Network layer: find the building address
  • Transport layer: find the room number
  • Together: deliver the parcel to the specific room

Instance:

When you visit a website:

  • Network layer: delivers the data to the server host (the IP address)
  • Transport layer: hands the data to the web server process (port 80)

Exercise 2

What is a port, what does it do, and how are ports classified?

portsport numbersaddressing

Approach

Define the port first, then list its four functions, then classify ports into the three IANA ranges with an example from each.

Steps

  1. State the definition: a 16-bit number in the transport layer that identifies a process.
  2. List the four functions of a port number.
  3. Give the three ranges and what each is allocated for.
  4. Add one example from each range.
  5. Close with the building analogy.

Answer

Definition of a port:

A port is the 16-bit number (0-65535) the transport layer uses to identify a process, just as a room number identifies a specific room inside a building.

Functions of a port:

  1. Process identification: uniquely identifies a process on a host
  2. Service differentiation: separates different network services
  3. Data dispatch: delivers data to the correct application process
  4. Connection management: distinguishes different connections in TCP

Classification of ports:

  1. Well-known ports (0-1023):

    • Allocated to common services
    • Administered centrally by IANA
    • Examples: HTTP (80), FTP (21), SSH (22)
  2. Registered ports (1024-49151):

    • Allocated to applications
    • Must be registered
    • Examples: MySQL (3306), Oracle (1521)
  3. Dynamic ports (49152-65535):

    • Allocated temporarily to clients
    • Assigned dynamically by the operating system
    • Released when the connection ends

Analogy:

  • Well-known ports: the public service zone of a building (reception, lifts)
  • Registered ports: the office zone (the company’s offices)
  • Dynamic ports: the temporary activity rooms (for occasional use)

Exercise 3

What are multiplexing and demultiplexing? Give an example of how the transport layer implements both.

multiplexingdemultiplexingports

Approach

Define each term with its analogy, then describe the sender path (multiplexing) and the receiver path (demultiplexing) separately, and finish with a concrete instance on both sides.

Steps

  1. Define multiplexing: several application processes sharing one transport layer service.
  2. Define demultiplexing: the transport layer dispatching data to the matching process.
  3. Describe the sender path: distinct ports, unified transport layer handling, one trip through the network layer.
  4. Describe the receiver path: extract the destination port, dispatch by port.
  5. Give the instance on both sides.

Answer

Definition of multiplexing:

Multiplexing means several application processes share the same transport layer service, in the same way several people share one telephone to make calls.

Definition of demultiplexing:

Demultiplexing means the transport layer distributes incoming data to the corresponding application process, in the same way a telephone exchange forwards an incoming call to a specific person.

Implementation:

Sender (multiplexing):

  • Several application processes use different port numbers
  • The transport layer handles them uniformly
  • They go out through the network layer

Receiver (demultiplexing):

  • The network layer receives the data
  • The transport layer extracts the destination port
  • The data is dispatched to the matching process

Worked instance:

Sender:

  • The browser (port 54321) sends a web page request
  • The mail client (port 54322) sends an email
  • The chat client (port 54323) sends a message
  • All of them go out through the transport layer

Receiver (the server):

  • Several packets arrive
  • Data on port 80 → the web server
  • Data on port 25 → the mail server
  • Data on port 8080 → the chat server

Analogy:

  • Multiplexing: several people making calls through the same telephone
  • Demultiplexing: an incoming call forwarded to a specific person by number

Exercise 4

How do TCP and UDP differ, and what scenarios suit each of them?

tcpudpprotocol selection

Approach

Compare the two protocols on the five dimensions that matter in practice, then map each to the scenarios it fits and state the decision rule.

Steps

  1. Compare the connection model.
  2. Compare reliability and ordering.
  3. Compare flow control and congestion control.
  4. Compare overhead and latency.
  5. List the scenarios for TCP and then for UDP.
  6. State the selection criteria.

Answer

The main differences are:

  1. Connection model:

    • TCP: connection-oriented, a connection has to be established
    • UDP: connectionless, data is sent directly
  2. Reliability:

    • TCP: guarantees reliable transmission
    • UDP: does not guarantee reliability
  3. Ordering:

    • TCP: guarantees ordered delivery
    • UDP: does not guarantee order
  4. Flow control:

    • TCP: has flow control
    • UDP: has no flow control
  5. Overhead and latency:

    • TCP: large overhead, high latency
    • UDP: small overhead, low latency

Scenarios:

Where TCP suits:

  • File transfer: data integrity matters
  • Web browsing: a complete page matters
  • Mail transfer: the message content matters
  • Database synchronisation: data accuracy matters

Characteristic: integrity and accuracy matter more than speed.

Where UDP suits:

  • Voice calls: strong real-time requirement
  • Live video: strong real-time requirement
  • Online games: speed first
  • DNS lookups: simple and fast

Characteristic: real-time behaviour and speed matter more than reliability.

How to decide:

  • If the data must not be lost → use TCP
  • If real-time behaviour matters → use UDP
  • If the volume is large → use TCP
  • If the volume is small → use UDP

Found an issue with this content?

Tell us what could be improved.