OSI Model·Lesson 7 of 12

Layer 4 — Transport

01

End-to-End Delivery

The Network layer gets a packet to the right device, but a single device runs many programs at once — a browser, a mail app, a music stream. Which one should the data go to? And what if a packet gets lost on the way? The Transport layer (Layer 4) answers both. It provides end-to-end delivery between the two actual programs that are communicating, and it can make that delivery reliable.

The one-liner

Layer 4 delivers data process-to-process — from the exact program on one device to the exact program on another — using port numbers. It can also add reliability: making sure everything arrives, in order, with nothing missing.

📬

Registered mail vs a postcard

Sending something important? You use registered mail — the courier tracks it, and you get a signed confirmation it arrived; if it's lost, it's re-sent. For a quick 'hello', a postcard is fine: cheap and fast, but nobody checks it got there. The Transport layer offers both styles — a careful, confirmed delivery (TCP) and a fast, no-guarantees one (UDP).

02

What It's Responsible For

The Transport layer sits between the applications above and the network below, and takes on the jobs that make program-to-program communication work:

Transport layer responsibilities

  • Segmentation and reassembly — breaking a large chunk of data into numbered segments, then rebuilding them in the right order at the other end
  • Port addressing — using port numbers to deliver data to the correct program on the device
  • Connection control — either setting up a connection first (connection-oriented) or just sending (connectionless)
  • Flow control — pacing the sender so it doesn't overwhelm the receiver, end to end
  • Error control — checking that segments arrived correctly and, if reliable, re-sending the ones that didn't
  • Congestion control — easing off when the network in between is getting overloaded
03

Port Numbers

The key to reaching the right program is the . If the IP address is like a building's street address, the port number is like an apartment number inside it — it points to one specific program. Your browser might use port 443 for a secure website while your mail app uses a different port, all on the same device. The combination of an IP address and a port number is called a socket, and it uniquely identifies one endpoint of a conversation.

04

The Two Transport Protocols: TCP and UDP

Almost all transport is done by one of two protocols. is the careful one: it sets up a connection, numbers every segment, waits for acknowledgements, and re-sends anything lost — so data arrives complete and in order. is the fast one: it just fires data off with no setup and no guarantees, which makes it lighter and quicker. Here's how they compare:

TCPUDP
ConnectionConnection-oriented (sets up first)Connectionless (just sends)
ReliabilityReliable — re-sends lost dataBest-effort — no guarantees
OrderingKeeps data in orderMay arrive out of order
SpeedSlower, more overheadFaster, lightweight
Data unitSegmentDatagram
Good forWeb, email, file transferStreaming, gaming, voice, DNS

How to choose

Need every byte to arrive correctly (a web page, a download, an email)? Use TCP. Need it fast and can tolerate a little loss (a live video, a voice call, a game)? Use UDP. A dropped frame in a video is better than freezing the whole stream to re-send it.

🚫

"UDP is just a broken version of TCP that nobody should use."

UDP is a deliberate design choice, not a bug. By skipping connection setup, acknowledgements, and retransmission, it delivers data with minimal delay — exactly what live video, voice calls, online games, and DNS lookups need. For those, speed matters more than perfect delivery.

Q:What does the Transport layer do, and how do TCP and UDP differ?

A: It provides process-to-process (end-to-end) delivery using port numbers, plus segmentation, flow control, error control, and congestion control. TCP is connection-oriented and reliable — it guarantees ordered, complete delivery via acknowledgements and retransmission. UDP is connectionless and best-effort — faster and lighter, but with no delivery or ordering guarantees. Its PDU is the segment (TCP) or datagram (UDP).

Quick Revision Cheat Sheet

Layer number: 4

Job: End-to-end (process-to-process) delivery

PDU (data unit): Segment (TCP) / Datagram (UDP)

Addressing: Port numbers (IP + port = socket)

TCP: Connection-oriented, reliable, ordered

UDP: Connectionless, best-effort, fast

Key tasks: Segmentation, flow, error, and congestion control