Course contents

Unit 7: TCP, UDP and PortsLesson 7.1.1 (1 of 23 in this unit)50 of 104 in the Network Fundamentals course

What the transport layer does

How does your laptop keep a web download separate from a call and an email connection? Let's follow the addresses and ports from one application to another.

Beginner · 6 min read

Covers Layer 4 role, Segments & datagrams and Multiplexing.

Technical definition

Transport layer (OSI Layer 4) is the layer that carries data between applications on two hosts, using port numbers to hand each segment or datagram to the right program. Its two main protocols are TCP, which is connection-oriented and reliable, and UDP, which is connectionless and lightweight.

A video call, a web page and a mail app on one laptop

You are on a video call. In another tab, a web page is loading, and your mail app is checking for new messages. All of this traffic arrives at the same laptop, with the same IP address. How does the laptop know which bytes belong to the call, which to the browser and which to the mail app?

IP cannot answer that question, because an IP address only identifies a device. The answer comes from the layer above IP: the transport layer, Layer 4 of the OSI model.

Two protocols, two styles of delivery

Start with a browser on PC-1 at 192.168.1.20. It opens a TCP connection from temporary port 52000 to a web service at 203.0.113.10:443. A temporary port is a local port chosen for this conversation. The server's replies are addressed back to port 52000, so the operating system can associate them with the correct socket, its application's network endpoint.

Diagram
The TCP conversation ends at the applications, not at R1
The TCP conversation ends at the applications, not at R1
The TCP conversation ends at the applications, not at R1PC-1 Ethernet at 192.168.1.20/24 connects through SW1 to R1 Gi0/0 at 192.168.1.1/24. R1 Gi0/1 at 203.0.113.1/24 connects to a server at 203.0.113.10/24. The example TCP connection is 192.168.1.20 port 52000 to 203.0.113.10 port 443. Replies reverse the endpoint addresses and ports. No NAT or TCP proxy is present.PC-1SW1R1ServerEth0 → Gi0/1Gi0/24Gi0/0Gi0/1Eth0192.168.1.20/24192.168.1.1/24203.0.113.1/24203.0.113.10/24Request: TCP 192.168.1.20:52000 → 203.0.113.10:443Reply: TCP 203.0.113.10:443 → 192.168.1.20:52000Gi0/0 is a physical interface name; TCP 443 is a transport-layer port number.

On small screens, swipe sideways or focus the diagram and use the arrow keys.

A routed lab with documentation addresses, no NAT and no TCP proxy. SW1 forwards frames, R1 routes packets, and the two endpoint TCP stacks maintain the connection. Both endpoints need a return route.

Follow the devices in order. SW1 carries the Ethernet frame across the local LAN. R1 removes that local framing and routes the IP packet to its other interface. In this lab, neither device terminates the browser's TCP connection. The IP addresses identify the endpoints, and TCP ports help identify the application conversation at those endpoints. The exact protocol, local address and port, and remote address and port matter; a port number alone is not the whole connection identity.

The transport layer moves data between two applications, not just two devices. It has two main protocols:

  • TCP (Transmission Control Protocol): careful and reliable. It sets up a connection first, numbers every byte and resends anything that gets lost.
  • UDP (User Datagram Protocol): simple and lightweight. It sends each message on its own and does not check whether it arrived.

A chunk of data plus a TCP header is called a segment. A chunk of data plus a UDP header is called a datagram. Either one then goes inside an IP packet, which goes inside a frame, such as an Ethernet frame. This wrapping is called encapsulation.

Diagram
One laptop, three applications, three ports
One laptop, three applications, three ports
LaptopIP 192.168.1.20RouterWeb serverTCP 443Mail serverTCP 993Media serviceUDP media

Device key: Media service (server)

Lines show the example’s network connections. Thick links: uplinks/WAN, as labelled. The coloured path and envelope follow the current step; its text identifies the sender, receiver and traffic type.

Reading the addresses

IP labels identify interfaces or destinations. Subnet labels identify networks; /n is the prefix length. A router ID (RID) identifies a routing process and need not be a reachable interface.

An IP address alone is not a URL. A web URL includes a scheme such as https://; an address on a router or printer does not imply a website.

  • Laptop: IP 192.168.1.20
  • Web server: TCP 443
  • Mail server: TCP 993
  • Media service: UDP media
  1. 1. Web page data arrives for the browser. Its destination port tells the laptop to pass it to the browser.
  2. 2. Mail data arrives with a different destination port, so it goes to the mail app.
  3. 3. Video call audio arrives over UDP, with its own port. One IP address, three separate conversations.

Six jobs, and which protocol does each

Diagram
Six jobs, and which protocol does each
Six jobs, and which protocol does each
JobWhat it meansTCPUDP
MultiplexingMany applications share one IP address; port numbers keep them apartYesYes
SegmentationLarge data is split into pieces that fit in packetsYesNo (the application keeps its messages small enough)
Connection setupBoth sides agree to communicate before data is sentYes (handshake)No
Reliable deliveryLost data is noticed and sent againYesNo
OrderingData is passed to the application in the order it was sentYesNo
Flow controlThe sender slows down when the receiver cannot keep upYes (windowing)No
Read each row across: the left box names the item, the others describe it.

Multiplexing means many conversations share one path. The sending side combines them; the receiving side uses the port numbers to separate them again (demultiplexing).

Why IP needs a layer above it

IP is best effort: it tries to deliver each packet, but it makes no promises. Packets can be lost, arrive twice or arrive in the wrong order, and IP does not resend them. Some applications cannot accept that: a downloaded file with one missing byte is broken. So TCP adds reliability on top of IP.

Some applications value a deadline more than recovering every old message. A voice application may discard a late audio frame rather than delay the conversation. UDP lets the application choose that behaviour, but does not guarantee low delay. Applications can add their own recovery and congestion control over UDP. Choosing TCP or UDP is a design trade-off, not a promise that one is faster in every case.

Seeing Layer 4 on your own computer

You can see the transport layer at work on any computer. The netstat and ss commands list your open connections. Each line shows a protocol (TCP or UDP), a local address and port, and a remote address and port. On a Cisco router, show control-plane host open-ports lists the TCP and UDP ports the router itself is listening on.

On a typical laptop the list is longer than most people expect: background updaters, sync clients and chat apps keep connections open even when nothing seems to be running.

Learn more: Viewing Connections on Your Computer

Test yourself on the transport layer

Predict · scenario 1

Your laptop receives two packets with the same destination IP address: one for the browser and one for the mail app. How does it know which application each belongs to?

Predict · scenario 2

In a packet capture, you look at a piece of application data with a TCP header in front of it. What is this unit called?

Predict · scenario 3

A DNS client and a voice app on the same PC both use UDP at the same time. Which transport layer job does UDP still do for them?

Technical references

RFC 9293: base TCP header, connection state, sequence space and delivery; RFC 768: UDP fields; RFC 8085: application responsibilities over UDP; RFC 9000: QUIC over UDP.