CS Atlas GATE 2027
Computer Networks course
0 / 90 complete

Computer Networks/Phase 4 · Transport Layer (TCP)

Lesson 4.1 · Item 60 of 90

Transport basics: process-to-process delivery, ports, sockets & multiplexing

Read at your own pace. Try the questions before opening the answers.

On this page

Recall warm-up

  1. What is the fundamental difference between what an IPv4 address identifies (Phase 3) and what a MAC address identifies (Phase 2)?
    Stuck? Peek at 3.4.5 Distance Vector vs Link State: full comparison, RIP & OSPF
    • DV (Bellman-Ford, RIP): sends all |V| distances to neighbours only; partial topology; vulnerable to count-to-infinity (∞ = 16).
    • LS (Dijkstra, OSPF): floods direct neighbour costs only (LSP) to all routers; full topology; O(V²) local compute; no count-to-infinity.
    • Both can oscillate if link cost = traffic load.

    Read lesson 3.4.5

  2. In Lesson 3.3 (NAT), how many bits long was the port number previewed in the NAPT translation table?
    Stuck? Peek at 3.3 Network Address Translation (NAT): private ranges, NAPT & trade-offs
    • Private IPv4 ranges: 10.0.0.0/8, 172.16.0.0/12 (172.16..31.x.y), 192.168.0.0/16.
    • NAPT table: maps (Private IP, Private Port) ↔ (Public IP, NAT Port).
    • Rewrites: Outgoing → Source IP + Source Port; Incoming → Destination IP + Destination Port (+ checksums).

    Read lesson 3.3

  3. What is the transport-layer PDU called in the Internet (TCP/IP) model?
    Stuck? Peek at 1.1.3 Encapsulation, headers, PDU names, addresses and devices per layer
    • Encapsulation: payload + header (+ trailer at data link); decapsulation in reverse.
    • PDUs: message (app) → segment (transport) → packet/datagram (network) → frame (data link) → bits.
    • Addresses: link (per hop, changes) · network (end to end, fixed) · which-program id · names.
    • Devices: hub/repeater 1 · bridge/switch 2 · router 3 · gateway/host up to 7.
    • Efficiency = data / (data + all headers + trailer).

    Read lesson 1.1.3

The Hook

Phase 3 carried our datagram across a dozen routers all the way to the destination computer's network card. Mission accomplished? Not quite! On your laptop right now, you have a browser with 5 tabs open, a chat app, a music streamer, and a software updater — all running on the same IPv4 address!

If the network layer is a postal carrier that drops all letters for a building at the front reception desk (host-to-host delivery), Phase 4 (the Transport Layer) is the internal mail clerk who reads the apartment number (the port number) and hands each segment to the exact running program (process-to-process delivery).

Predict First

Two different laptops (10.0.0.1 and 10.0.0.2) both happen to pick the exact same ephemeral source port 50000 and connect to the same server 203.0.113.10 on port 80. When the server receives segments from both laptops on port 80, how does the server's transport layer tell the two connections apart?

,

Because a connection-oriented (TCP) socket is identified by the full 4-tuple (Source IP, Source Port, Destination IP, Destination Port)! Since the Source IPs (10.0.0.1 vs 10.0.0.2) differ, the two 4-tuples are completely distinct even though both source ports and destination ports are identical!

Core Concept

Host-to-Host (L3) vs Process-to-Process (L4) & Port Numbers

While the Network Layer delivers packets between hosts, the Transport Layer runs entirely in the end hosts to deliver segments between processes (running programs).

Port number: a 16-bit unsigned integer (0 to 65,535) that identifies a communication endpoint (process/socket) on a host. Divided by IANA into three ranges:
• Well-known ports (0 – 1023): reserved for standard server services (e.g., 20/21, 22, 25, 53, 80, 443).
• Registered ports (1024 – 49151): assigned for user/vendor server applications.
• Ephemeral / Dynamic ports (49152 – 65535): assigned temporarily by the client OS when a client program initiates a connection.
Well-Known (0–1023)0–7
Registered (1024–49151)8–47
Ephemeral / Dynamic (49152–65535)48–63
063
The 16-bit port number space (0 to 65,535; drawn schematically across 64 units).

Socket Addresses, Multiplexing & Demultiplexing

The combination of an IP address and a port number is called a socket address, written IP:Port (e.g., 192.168.1.10:51234).

  • Transport Multiplexing (at sender): Gathering data chunks from multiple sockets, tagging each with a transport header (containing source and destination ports), and passing segments down to the single network layer.
  • Transport Demultiplexing (at receiver): Inspecting the header fields of an arriving segment to deliver it to the correct socket:
    — Connectionless demultiplexing (UDP) uses a 2-tuple (Destination IP, Destination Port).
    — Connection-oriented demultiplexing (TCP) uses a 4-tuple (Source IP, Source Port, Destination IP, Destination Port).
UDP Demultiplexing (2-tuple)
Looks ONLY at (Dst IP, Dst Port). Segments from two different clients to the same server port go into the SAME server socket queue!
TCP Demultiplexing (4-tuple)
Looks at (Src IP, Src Port, Dst IP, Dst Port). Each client connection gets its own dedicated connected socket at the server!
Why a TCP server has one socket per active client, while a UDP server shares one socket for all clients.

Reliable Connection-Oriented (TCP) vs Best-Effort (UDP)

The Internet provides two transport protocols on top of best-effort IPv4:

  • TCP (Transmission Control Protocol): Connection-oriented (sets up state before data flows), reliable (recovers lost or corrupted segments in order), with flow control (protects slow receivers) and congestion control (protects overloaded network routers).
Foundation — UDP (User Datagram Protocol): UDP is a minimal, connectionless, best-effort transport protocol (IP Protocol number 17 vs TCP's 6). A UDP header is just 8 bytes long: four 16-bit fields — Source Port (16b), Destination Port (16b), UDP Length (16b, header + data in bytes, min 8), and UDP Checksum (16b). UDP adds process-to-process demultiplexing and an optional checksum over IP, with zero setup delay and no retransmission, flow control, or congestion control.
048162431
Source Port (16)16 bits
Destination Port (16)16 bits
UDP Length (16)16 bits
UDP Checksum (16)16 bits
Foundation: The fixed 8-byte UDP header (two 32-bit rows).

Putting it together

  • The Transport Layer extends host-to-host IP delivery into end-to-end process-to-process delivery using 16-bit port numbers.
  • A socket address pairs an IP address with a port number; TCP identifies connections by a 4-tuple while UDP uses a 2-tuple.
  • TCP provides reliable, connection-oriented byte-stream delivery, whereas UDP (Foundation) provides a minimal 8-byte connectionless wrapper.

Visual

Process P1 (Port 50001)
Transport Layer (L4)
Multiplexes: adds Src/Dst Port
Network Layer (L3)
Host-to-host via IP
Transport Layer (L4)
Demultiplexes via 2-tuple / 4-tuple
Server Process (Port 80)
Logical end-to-end process-to-process delivery built on top of host-to-host IP delivery.

Worked Examples

Easy

How many total port numbers exist in TCP/UDP, and which range is reserved for well-known server ports?

Show the full solution

A port number is 16 bits → 2¹⁶ = 65,536 port numbers (0 to 65,535). Well-known ports are 0 to 1023 (1,024 ports).

Medium

A UDP segment carries 140 bytes of application data. What value is stored in the 16-bit UDP Length field?

Show the full solution

The UDP header is a fixed 8 bytes, and UDP Length measures the entire UDP datagram (header + payload): 140 + 8 = 148 bytes.

GATE

Client A (10.0.0.1) opens two browser tabs to Server S (198.51.100.5:80), and Client B (10.0.0.2) opens one tab to the same Server S (198.51.100.5:80) over TCP. Can Client A's two tabs use the same source port? Can Client B use the same source port as one of Client A's tabs?

Show the full solution

At Server S, TCP demultiplexes using the 4-tuple (Src IP, Src Port, Dst IP, Dst Port):
• For Client A's two tabs, Src IP, Dst IP, and Dst Port are all identical — so Client A's two tabs MUST use different ephemeral source ports (e.g., 50001 and 50002) to keep the 4-tuples distinct!
• Client B has a different Src IP (10.0.0.2), so Client B CAN use source port 50001 without any collision!

GATE Traps

  • TCP port 80 and UDP port 80 are completely independent! TCP and UDP maintain separate port tables (distinguished by the IPv4 Protocol field: 6 vs 17).
  • Routers do not run Transport Layer demultiplexing: Transport multiplexing and demultiplexing happen only at the source and destination hosts (end-to-end).

Memory Hook

IP finds the building (32-bit host address); Port knocks on the apartment door (16-bit process address); TCP checks all 4 badges on the envelope!

Connect the Dots

We now know how segments reach the right process via ports and sockets. After the Chapter 4.1 Lock-in, Chapter 4.2 builds the second pillar of TCP from first principles: how do we turn an unreliable packet network that drops and corrupts packets into a 100% reliable, high-speed pipeline?

Self-Test

  1. NAT

    How many distinct port numbers can be represented by the 16-bit port field in a transport-layer header?

    Write your answer before opening the key.

  2. MCQ

    Which tuple of fields is used by the receiving host’s TCP implementation to demultiplex an arriving TCP segment to the correct connected socket?

    1. Only (Destination Port)
    2. (Destination IP, Destination Port)
    3. (Source IP, Source Port, Destination IP, Destination Port)
    4. (Source MAC, Destination MAC, Source Port, Destination Port)
  3. MSQ

    Which of the following statements about Transport Layer ports, UDP, and TCP are TRUE?

    1. A client process initiating a connection is typically assigned an ephemeral port number by its operating system.
    2. Two different client hosts (with different IP addresses) can simultaneously connect to the same TCP server port using the exact same client source port number.
    3. The UDP header has a fixed length of 8 bytes.
    4. Intermediate IP routers use the TCP 4-tuple to forward packets in standard IP routing.
  4. NAT

    How many bytes long is the fixed UDP header?

    Write your answer before opening the key.

Rule Card

  • Delivery: Network Layer = host-to-host; Transport Layer = process-to-process.
  • Port number = 16 bits (0–65,535): Well-known 0–1023, Registered 1024–49151, Ephemeral 49152–65535.
  • Demultiplexing: UDP uses 2-tuple (DstIP, DstPort); TCP uses 4-tuple (SrcIP, SrcPort, DstIP, DstPort).
  • UDP (Foundation) = 8-byte header, connectionless, best-effort; TCP = connection-oriented, reliable, flow + congestion controlled.

Concept Ledger

  • process-to-process delivery
  • port number (16-bit, 0–65535)
  • well-known / registered / ephemeral ports
  • socket address (IP, port)
  • multiplexing and demultiplexing
  • reliable vs best-effort delivery
  • TCP (reliable, connection-oriented)
  • UDP (8-byte header — Foundation)

Answer Vault

Try the questions first. Open when you are ready to check.

Warm-up answers

  1. A MAC address identifies a network interface card on the local LAN (hop-to-hop), whereas an IPv4 address identifies the host interface across the global Internet (host-to-host).
  2. 16 bits (0 to 65535).
  3. A segment (or user datagram for UDP).

Self-test answers

  1. 65536 — 2¹⁶ = 65,536 port numbers (ranging from 0 to 65,535).
  2. C — Connection-oriented TCP demultiplexes using the 4-tuple (Source IP, Source Port, Destination IP, Destination Port).
    • A: Too narrow; multiple IP interfaces and clients exist.
    • B: That is the 2-tuple used by connectionless UDP.
    • D: MAC addresses belong to Layer 2 and are stripped before Layer 4.
  3. ABC — Clients use ephemeral ports; different client IPs make the TCP 4-tuples distinct; UDP header is 8 bytes. Standard IP routers look only at the Layer-3 Destination IP.
    • D: Standard IP routers inspect only the Layer-3 IPv4 header, not transport ports.
  4. 8 — UDP has four 16-bit (2-byte) fields: Source Port, Destination Port, Length, and Checksum → 4 × 2 = 8 bytes.

Flashcards

  1. What is a socket address?
    Reveal answerThe pair (IP Address, Port Number) identifying a specific process endpoint on a specific host.
  2. How does TCP demultiplexing differ from UDP demultiplexing?
    Reveal answerTCP uses the 4-tuple (Src IP, Src Port, Dst IP, Dst Port); UDP uses the 2-tuple (Dst IP, Dst Port).
  3. What are the three port number ranges?
    Reveal answerWell-known: 0–1023; Registered: 1024–49151; Ephemeral: 49152–65535.
  4. What are the 4 fields of the 8-byte UDP header?
    Reveal answerSource Port (16b), Destination Port (16b), UDP Length (16b), UDP Checksum (16b).

Exam shortcuts

  • TCP 4-tuple vs UDP 2-tuple: Two TCP connections collide iff ALL FOUR of (SrcIP, SrcPort, DstIP, DstPort) are identical; two UDP packets go to the same socket iff (DstIP, DstPort) are identical. — every GATE demultiplexing question.
  • UDP 8-byte rule: 4 fields × 2 bytes = 8 bytes (no HLEN field needed because UDP has no options!). — Foundation header size comparisons.

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.