The Big Idea
A port is a logical communication endpoint on a computer. While an IP address identifies which device on a network is being addressed, a port identifies which specific application or service on that device should receive the data. Ports allow thousands of networked applications to operate on a single machine without interfering with one another. They form a core part of how the transport layer of the TCP/IP model directs traffic to the appropriate process.
The idea of ports are closely connected to sockets. neither will be assessed by the IB, but it's a good idea for you to be familiar with them.
Why Ports Exist
Primary memory and network stacks are finite resources. A single device typically runs many networked programs simultaneously—web browsers, messaging apps, streaming services, SSH daemons, update services. Network packets arriving at the device must be delivered to the correct process. Ports provide the mechanism for this multiplexing.
Analogy:
- Your street address identifies your house (IP address).
- But inside your house, different rooms serve different purposes. A port number is like a room number that directs a visitor to the correct room.
What Exactly Is a Port?
Technically, a port is a 16-bit unsigned integer used by the transport layer (TCP or UDP) to distinguish between simultaneous network conversations. Common examples include:
- Port 80 — HTTP (web traffic)
- Port 443 — HTTPS (encrypted web traffic)
- Port 22 — SSH
- Port 53 — DNS
- Port 3306 — MySQL/MariaDB
- Port 5000/8000 — Common developer testing servers
These numbers are agreed-upon standards defined by the IANA so that client and server software can interoperate.
IB DP Computer Science requires you to describe the function of protocols (A2.1.4) and explain how data transmission occurs through layers of the TCP/IP model (A2.3.3, A2.1.5). Ports are part of the transport layer’s responsibility.
How Ports Work in TCP and UDP
Both TCP and UDP use ports, but the way they use them aligns with their transport-layer semantics.
TCP Ports
TCP is connection-oriented. When your browser loads a webpage, it creates a TCP connection between:
Client: (your IP, ephemeral port)
Server: (server IP, port 443)
The ephemeral port is randomly chosen by the OS from a high-numbered range (typically 49152–65535). TCP then uses a socket pair:<source IP, source port, destination IP, destination port>
to uniquely identify the connection.
UDP Ports
UDP is connectionless. It still uses ports, but without stateful handshakes. For example, DNS queries (port 53) simply send a datagram to the server.
Port Ranges
Ports are divided into standard ranges based on how they are normally used:
- Well-Known Ports (0–1023)
Reserved for standard services (SSH, HTTP, DNS). - Registered Ports (1024–49151)
Assigned to specific applications (databases, APIs, game servers). - Ephemeral Ports (49152–65535)
Used temporarily by clients to initiate outbound connections.
This structure supports both predictable service locations and flexible session management.
Example: How Ports Enable Web Browsing
When a student visits a website, this sequence occurs:
- Browser opens an ephemeral port, e.g., 53012.
- Browser sends request to server at port 443.
- Server responds from 443 → client’s ephemeral port.
- Browser and server exchange packets until the connection closes.
Without ports, the operating system would have no method to deliver the returning packets to the correct browser tab or process.
Ports and Security
Ports are also critical in network security, an HL-only topic under A2.4 (network vulnerabilities and countermeasures).
- Open ports expand attack surface.
- Firewalls allow or block traffic based on port rules.
- Scanning for open ports is a common reconnaissance technique.
- Secure protocols shift to encrypted ports (HTTP → HTTPS).
Firewalls often filter traffic using rules such as:
- “Block inbound TCP on port 23”
- “Allow outbound UDP on port 53”
This mapping between services and ports enables administrators to control network behavior precisely.
Good Use of Command Terms
Explain:
A strong explanation identifies the concept, provides reasons, and uses a clear causal chain.
Example of strong IB-style explanation:
“Ports enable multiplexing by providing unique numerical identifiers for processes. Without ports, the OS could not determine which application should receive incoming packets. Therefore ports are essential for supporting simultaneous network communication.”
Weak explanation:
“Ports help data go to the right app.”
Summary
- Ports are logical endpoints used by TCP and UDP to deliver packets to the correct process.
- They enable multiple simultaneous network connections on a single device.
- They are standardized into well-known, registered, and ephemeral ranges.
- Security tools like firewalls rely on port-based filtering.
- Understanding ports forms a foundation for networks, packet switching, routing, and application-layer protocols in the IB DP Computer Science syllabus.