Transport Layer Fundamentals
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.1 End-to-End Process Communication: The Final Link in Network Communication
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
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:
| Layer | Analogy | Network layer |
|---|---|---|
| Find the building | Find the building address | Network layer: find the host (IP address) |
| Find the room | Find the specific room number | Transport layer: find the process (port number) |
| Find the person | Find the specific person | Application 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.
| Layer | Analogy | Actual content |
|---|---|---|
| Application layer | Hand it to Zhang San | Process: the browser |
| Transport layer | Building 3, Unit 5, Room 602 | Port: 80 |
| Network layer | No. XX, XX Street, Chaoyang District, Beijing | IP 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
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
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 analogy | Network analogy |
|---|---|
| Building address | IP address (host) |
| Room number | Port number (process) |
| Room occupant | A specific process |
| Function of the room | Type of service |
What port numbers do:
- Identify a process: tell the data which process it belongs to
- Distinguish services: separate different network services (HTTP, FTP, and so on)
- Manage connections: distinguish different connections in TCP
- Dispatch data: deliver data to the correct application
Classification of Port Numbers
Port number range: 0-65535 (16 bits, 65536 ports in total)
They fall into three classes, just as the rooms of a building fall into different zones:
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:
| Port | Service | Description | Analogy |
|---|---|---|---|
| 20/21 | FTP | File transfer | The parcel room |
| 22 | SSH | Secure remote login | The VIP entrance |
| 23 | Telnet | Remote login | The ordinary entrance |
| 25 | SMTP | Sending mail | The mail drop box |
| 53 | DNS | Name resolution | The directory enquiry desk |
| 80 | HTTP | Web service | The information desk |
| 110 | POP3 | Receiving mail | The mail collection box |
| 143 | IMAP | Mail access | The reading room |
| 443 | HTTPS | Secure web | The 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:
| Port | Service | Description |
|---|---|---|
| 1433 | MS SQL Server | The Microsoft database |
| 1521 | Oracle | The Oracle database |
| 3306 | MySQL | The MySQL database |
| 5432 | PostgreSQL | The PostgreSQL database |
| 6379 | Redis | The Redis cache |
| 8080 | HTTP Proxy | The 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:
- The program that starts first takes the port
- The program that starts second reports “port already in use”
- 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
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
Multiplexing means that several application processes share a single transport layer service, in the same way several people share one telephone to make calls.
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
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:
- Check the destination port: 80 (the HTTP service)
- Look up the process bound to that port: the web server process
- Hand the data to that process
- The process handles the data
A concrete example:
Scenario: the server receives several requests.
| Request | Source IP | Source port | Destination port | Content |
|---|---|---|---|---|
| Request 1 | 192.168.1.10 | 54321 | 80 | Web page request |
| Request 2 | 192.168.1.11 | 54322 | 25 | Mail 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
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
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.
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
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:
- Segment the data
- Add a checksum
- Send the segment
Receiver:
- Receive the segment
- Compute the checksum
- Compare it with the sender’s checksum
- If they do not match, discard the segment
- 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:
- Sequence numbers: every byte is numbered, so the order of the data is preserved
- Acknowledgements: the receiver confirms receipt and the sender learns that the data has arrived
- Retransmission: unacknowledged data is sent again, so nothing is lost
- Flow control: the sending rate is controlled so the receiver is not overloaded
- 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.1 Comparison by Layer Function
| Aspect | Network layer | Transport layer |
|---|---|---|
| Scope of communication | Host to host | Process to process |
| Addressing | IP address | Port number |
| Reliability | Not guaranteed (best effort) | Can be guaranteed (TCP) |
| Flow control | None | Present (TCP) |
| Connection model | Connectionless (IP) | Connectionless (UDP) / connection-oriented (TCP) |
| Serves | Hosts | Processes |
| Analogy | Finding the building | Finding 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.1 TCP: Reliable Transmission
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
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
| Scenario | Characteristic | Why TCP is used |
|---|---|---|
| File transfer | Data integrity matters | Not a single byte may be lost |
| Web browsing | A complete page matters | Part of a page may not be lost |
| Mail transfer | The message content matters | The body of the mail may not be lost |
| Database synchronisation | Data accuracy matters | No error at all is acceptable |
Real examples that use TCP:
- Downloading a file: FTP (port 21)
- Browsing the web: HTTP (port 80)
- Sending mail: SMTP (port 25)
- Remote login: SSH (port 22)
3.2 UDP: Fast Transmission
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
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
| Scenario | Characteristic | Why UDP is used |
|---|---|---|
| Voice calls | Strong real-time requirement | A few lost packets do not spoil the call |
| Live video | Strong real-time requirement | A few dropped frames do not spoil the viewing |
| Online games | Strong real-time requirement | Speed matters more than reliability |
| DNS lookups | Simple and fast | One request, one response |
Real examples that use UDP:
- DNS lookups: UDP (port 53)
- Voice calls: UDP (strong real-time requirement)
- Live video: UDP (strong real-time requirement)
- Online games: UDP (speed first)
3.3 TCP vs UDP
| Feature | TCP | UDP |
|---|---|---|
| Connection model | Connection-oriented | Connectionless |
| Reliability | Guaranteed | Not guaranteed |
| Ordering | Guaranteed | Not guaranteed |
| Flow control | Present | Absent |
| Congestion control | Present | Absent |
| Transmission efficiency | Lower | Higher |
| Latency | Higher | Lower |
| Overhead | Large | Small |
| Typical use | File transfer, web pages | Real-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.
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.
- Application layer: the browser issues an HTTP request
- 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
- Network layer:
- IP address: the client
192.168.1.10→ the server202.108.22.5 - Routing and forwarding: the packets reach the server hop by hop
- IP address: the client
- 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
- 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.
- Application layer: the browser needs the domain name resolved
- Transport layer (UDP):
- Client port: 49152 (an ephemeral port)
- DNS server port: 53
- The DNS query request is sent as a UDP datagram
- Network layer: client IP → DNS server IP
- The DNS server:
- Receives the UDP datagram
- Looks up the IP for the domain
- Returns the IP address as a UDP datagram
- 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
- Receives the UDP response and obtains the IP address:
Characteristics: UDP is simple and fast, one request produces one response, no connection has to be established, and the response comes back quickly.
Exercise 1
What is the difference between the transport layer and the network layer, and how do the two cooperate?
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
- Compare the scope of communication: host-to-host against process-to-process.
- Compare the addressing mechanism: IP address against port number.
- Compare the reliability guarantee: best effort against TCP’s guarantee.
- Compare flow control: absent at the network layer, present in TCP.
- Explain the cooperation: the network layer finds the host, the transport layer finds the process.
- Close with a concrete instance.
Answer
The main differences are:
-
Scope of communication:
- Network layer: host to host (finds the IP address)
- Transport layer: process to process (finds the port number)
-
Addressing mechanism:
- Network layer: IP address (32 bits or 128 bits)
- Transport layer: port number (16 bits)
-
Reliability:
- Network layer: not guaranteed, best effort
- Transport layer: guaranteed by TCP, not by UDP
-
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?
Approach
Define the port first, then list its four functions, then classify ports into the three IANA ranges with an example from each.
Steps
- State the definition: a 16-bit number in the transport layer that identifies a process.
- List the four functions of a port number.
- Give the three ranges and what each is allocated for.
- Add one example from each range.
- 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:
- Process identification: uniquely identifies a process on a host
- Service differentiation: separates different network services
- Data dispatch: delivers data to the correct application process
- Connection management: distinguishes different connections in TCP
Classification of ports:
-
Well-known ports (0-1023):
- Allocated to common services
- Administered centrally by IANA
- Examples: HTTP (80), FTP (21), SSH (22)
-
Registered ports (1024-49151):
- Allocated to applications
- Must be registered
- Examples: MySQL (3306), Oracle (1521)
-
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.
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
- Define multiplexing: several application processes sharing one transport layer service.
- Define demultiplexing: the transport layer dispatching data to the matching process.
- Describe the sender path: distinct ports, unified transport layer handling, one trip through the network layer.
- Describe the receiver path: extract the destination port, dispatch by port.
- 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?
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
- Compare the connection model.
- Compare reliability and ordering.
- Compare flow control and congestion control.
- Compare overhead and latency.
- List the scenarios for TCP and then for UDP.
- State the selection criteria.
Answer
The main differences are:
-
Connection model:
- TCP: connection-oriented, a connection has to be established
- UDP: connectionless, data is sent directly
-
Reliability:
- TCP: guarantees reliable transmission
- UDP: does not guarantee reliability
-
Ordering:
- TCP: guarantees ordered delivery
- UDP: does not guarantee order
-
Flow control:
- TCP: has flow control
- UDP: has no flow control
-
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
