TCP/IP Model·Lesson 4 of 8

Transport Layer

01

Getting Data to the Right Program

The transport layer sits just below the application layer, and its job is end-to-end delivery: making sure data sent by one program arrives at the correct program on another device. Notice the word program. Your laptop might be running a browser, a music app, and a chat app all at once — so it isn't enough to get data to the right machine; it has to reach the right (a running program) on that machine. The transport layer is what keeps those conversations sorted out.

Two protocols, one layer

The transport layer offers two main protocols: TCP (reliable and ordered) and UDP (fast and lightweight). It uses port numbers to know which program a piece of data belongs to.

🏢

The apartment building

Imagine a large apartment building. The street address gets a letter to the right building — that's the job of the IP address at the layer below. But the building has hundreds of flats, so the letter also needs an apartment number to reach the right resident. The port number is that apartment number: it tells the transport layer exactly which program inside the machine should receive the data.

02

Ports: Which App Gets the Data

A is a number that identifies a specific program or service on a device. When data arrives, the transport layer reads the port number to decide which program to hand it to. Many services use well-known ports so everyone can find them: web traffic uses port 80 for HTTP and 443 for HTTPS, DNS uses 53, and email sending (SMTP) uses 25. Combine a device's IP address with a port number and you get a socket — the exact endpoint of a connection.

03

TCP vs UDP — The Big Choice

The transport layer gives applications two very different ways to send data, and choosing between them is one of the most important decisions in networking. TCP (Transmission Control Protocol) is careful and reliable; UDP (User Datagram Protocol) is fast and simple. Here's how they compare:

TCPUDP
ConnectionConnection-oriented (sets up first)Connectionless (just sends)
ReliabilityGuaranteed — resends lost dataBest-effort — no guarantee
OrderingDelivers data in orderMay arrive out of order
Speed / overheadSlower, more overheadFaster, very little overhead
Best forWeb, email, file transferVideo, voice, gaming, DNS

The rule of thumb: choose TCP when every byte must arrive correctly and in order — loading a web page, sending an email, downloading a file. Choose UDP when speed matters more than perfection and a little lost data is acceptable — a live video call or an online game would rather skip a dropped frame than pause to re-send it.

How to answer "which should I use?"

Tie it to the cost of a lost packet. If losing data breaks things (a bank transfer, a file), use TCP. If waiting for re-sent data is worse than losing it (live audio, video, gaming), use UDP.

04

Breaking Data Into Segments

Applications often hand over more data than can be sent in one go, so the transport layer chops it into smaller pieces called . Each segment gets a header with the port numbers and, for TCP, a sequence number so the pieces can be put back in the right order at the other end. This splitting is called segmentation, and rebuilding the original data on the receiving side is called reassembly.

05

How It Fits With Its Neighbours

The transport layer takes data from the above, splits it into segments, and passes them down to the below, which adds IP addresses and handles routing. It's a clean division of labour: the transport layer promises to get data to the right program in the right shape, and trusts the internet layer to actually carry each piece across the network.

🚫

"TCP is always the better choice because it's reliable."

Reliability isn't free — TCP's acknowledgements, ordering, and re-sends add delay. For live video, voice, or gaming, that delay is worse than the occasional lost packet, so UDP is the better fit. The 'best' protocol depends entirely on what the app needs.

Q:What is the main job of the transport layer?

A: To provide end-to-end delivery between programs. It uses port numbers to reach the right process, splits data into segments, and offers two protocols: TCP for reliable, ordered delivery, and UDP for fast, connectionless, best-effort delivery.

Quick Revision Cheat Sheet

Job: End-to-end delivery to the right program

Addressing: Port numbers identify the process

TCP: Reliable, ordered, connection-oriented — slower

UDP: Fast, connectionless, best-effort — no guarantees

Data unit: Segment

Sits between: Application (above) and Internet (below)