Computer Networks

Ports

16-bit transport addresses that multiplex a host. Well-known, registered, ephemeral.

Level: beginner

What is it?

A transport port is a 16-bit number used with an IP address and transport protocol to identify an application endpoint. Ports let many applications communicate concurrently through the same network interface, for example a web server on one port and a DNS service on another.

Why does it matter?

IP directs packets to a host/interface, while ports help the transport layer deliver data to the correct socket or service on that host. A port number alone is not globally unique; the protocol and endpoint address context matter.

Mental model

Think of an IP address as a building and a port as a service desk inside it. TCP and UDP each have their own port space, and client processes often use ephemeral source ports.

How it works

  • The 16-bit port field ranges from 0 through 65535.
  • Well-known and registered port assignments are conventions managed through IANA; real services may use nondefault ports.
  • A connection is identified by a tuple including protocol, local/remote IP addresses, and local/remote ports.
  • A listening TCP socket is different from an established TCP connection.
  • Port reachability depends on local listeners, routing, firewalls, NAT, and the application's protocol behavior.

Steps

  • A browser opens a TCP connection to a web server at destination port 443.
  • The client chooses an ephemeral source port.
  • The OS demultiplexes incoming segments using the connection/socket tuple.
  • The server's listener accepts the connection and the application speaks HTTPS over it.

Real-world usage

  • Debugging a service that is not listening on the expected port.
  • Understanding ephemeral ports and NAT translation.
  • Reading netstat/ss output and firewall rules.

Common mistakes

  • Treating a port number as an identity independent of IP and protocol.
  • Assuming port 443 guarantees the service is HTTPS.
  • Confusing an open TCP listener with UDP reachability.

Interview questions

What identifies a TCP connection?

Typically the local and remote IP addresses and ports plus the transport protocol, with protocol state tracked by the stack.

Can TCP and UDP both use port 53?

Yes. They have distinct transport protocol spaces, even though DNS commonly uses both in different situations.

Prerequisites

Related concepts

Continue learning

Browse the full computer science library