100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

What is the Transport Layer (OSI Layer 4)?

Learn what the OSI Transport layer does, TCP vs UDP, ports, sockets, and flow control, with networking interview questions.

mediumQ28 of 224 in Computer Networks Est. time: 6 minsLast updated:
Open Code Lab

Expected Interview Answer

The Transport layer is OSI Layer 4 โ€” it manages end-to-end communication between applications on two hosts, using port numbers to distinguish processes and providing either reliable, ordered delivery (TCP) or fast, connectionless delivery (UDP).

Where the Network layer only gets a packet from one host to another, the Transport layer is what makes sure the right application on that host receives the data, and, for TCP, that it arrives complete and in order. TCP achieves reliability through the three-way handshake, sequence numbers, acknowledgements, retransmission of lost segments, and flow/congestion control (via mechanisms like the sliding window and slow start). UDP skips all of that overhead, sending independent datagrams with no guarantee of delivery or order, which suits latency-sensitive use cases like video calls, DNS lookups, and online gaming where retransmitting a stale packet is often worse than dropping it. Port numbers (0-65535) at this layer, combined with an IP address, form a socket โ€” the unique combination that identifies a specific communication endpoint, allowing a single host to run many simultaneous connections.

  • Multiplexes multiple applications on one host via port numbers
  • TCP provides reliable, ordered, retransmitted delivery
  • UDP provides low-latency, connectionless delivery when speed matters more than reliability
  • Implements flow and congestion control to avoid overwhelming a receiver or the network

AI Mentor Explanation

The Transport layer is like the difference between a courier confirming a signed delivery of a trophy (TCP) versus simply shouting the live score across the ground to anyone listening (UDP) โ€” the trophy delivery requires a receipt and a resend if lost, while the shouted score is not worth resending if a fan mishears one number, since a fresher score is already on the way. The specific person the courier hands the trophy to, versus a general announcement, mirrors a port number identifying the exact application waiting for data. Both mechanisms exist because different information demands different guarantees โ€” the Transport layer is what offers that choice.

Step-by-Step Explanation

  1. Step 1

    Port multiplexing

    The Transport layer uses port numbers to direct data to the correct application on the host.

  2. Step 2

    Protocol choice

    TCP is chosen for reliability (handshake, acknowledgements, retransmission) or UDP for speed.

  3. Step 3

    Flow/congestion control

    TCP paces data using a sliding window and congestion control to avoid overwhelming the receiver or network.

  4. Step 4

    Delivery to socket

    Data is delivered to the exact socket (IP + port) identifying the receiving application.

What Interviewer Expects

  • Clear definition: end-to-end delivery between applications via port numbers
  • Compares TCP (reliable) vs UDP (fast, connectionless) with concrete use cases
  • Understands sockets as the IP + port combination
  • Aware of flow control and congestion control concepts in TCP

Common Mistakes

  • Confusing port numbers (Transport layer) with IP addresses (Network layer)
  • Thinking UDP is unreliable in every case with no legitimate use
  • Not knowing TCPโ€™s reliability comes from ACKs, sequence numbers, and retransmission
  • Forgetting that a socket is the IP + port pair, not just the port alone

Best Answer (HR Friendly)

โ€œThe Transport layer is what makes sure data reaches the right application on a destination computer, not just the right computer. It offers two options: TCP, which double-checks everything arrived correctly and in order, like a tracked delivery, and UDP, which just sends data quickly without guarantees, which is perfect for things like video calls where speed matters more than perfection.โ€

Code Example

Inspecting Transport layer connections and ports
# List active TCP and UDP connections with local/remote ports
ss -tulnp

# Example output:
# tcp  LISTEN  0  128  0.0.0.0:443   0.0.0.0:*  users:(("nginx",pid=1234))
# udp  UNCONN  0  0    0.0.0.0:53    0.0.0.0:*  users:(("dnsmasq",pid=987))

Follow-up Questions

  • How does TCPโ€™s sliding window enable flow control?
  • What is the difference between flow control and congestion control?
  • Why is UDP preferred for DNS queries and video streaming?
  • What is a socket and how does it combine IP address and port?

MCQ Practice

1. What identifies a specific application process at the Transport layer?

Port numbers, combined with the IP address, identify the exact socket an application listens on.

2. Which Transport layer protocol guarantees ordered, reliable delivery?

TCP provides reliable, ordered delivery via sequence numbers, acknowledgements, and retransmission.

3. Why is UDP often preferred for live video calls?

UDP skips handshakes and retransmission, favoring low latency over guaranteed delivery, ideal for real-time media.

Flash Cards

What is the Transport layer? โ€” OSI Layer 4 โ€” manages end-to-end delivery between applications using port numbers.

TCP vs UDP? โ€” TCP is reliable and ordered (connection-based); UDP is fast and connectionless (no guarantees).

What is a socket? โ€” The unique combination of an IP address and a port number identifying a communication endpoint.

What does TCP congestion control do? โ€” Paces data transmission to avoid overwhelming the network, e.g. via slow start.

1 / 4

Continue Learning