</>
ShikshaCSLearn. Code. Grow.
๐Ÿ”
โ˜• Support Us
ShikshaCSโ€บNotesโ€บComputer Networks
Computer Networks
๐Ÿ•’ 8 min read

Sockets and Ports

How one device juggles hundreds of network connections at once without mixing them up.

The Problem: One IP, Many Conversations

Your laptop has ONE IP address, but you might have a browser with 10 open tabs, a music streaming app, and a chat app ALL talking to the internet simultaneously. If data just arrived at your IP address with no further detail, your device would have no way to know which app each piece of data belongs to.

What is a Port?

A port is a numbered 'channel' (0-65535) that helps direct incoming data to the correct application on a device. Certain 'well-known' ports are reserved for common services: port 80 for HTTP (web), port 443 for HTTPS (secure web), port 25 for SMTP (email sending), port 53 for DNS โ€” when your browser connects to a website, it's specifically targeting port 80 or 443 on the server.

What is a Socket?

A socket is the combination of an IP address AND a port number together (written like 192.168.1.5:8080) โ€” this combination uniquely identifies ONE specific ongoing conversation between two devices. Since each browser tab typically uses a different random port on your device (while the server side commonly uses port 80/443), many simultaneous conversations to the same website can be told apart cleanly.

How a Server Handles Many Clients

A web server listens on one well-known port (like 443 for HTTPS), but can serve THOUSANDS of different clients at once โ€” this works because each individual connection is uniquely identified by the FULL combination of source IP+port and destination IP+port together, not by the server's port alone. Two different visitors both connecting to port 443 remain completely distinguishable because their own IP+port combinations differ.

Ephemeral (Temporary) Ports

When your device INITIATES a connection (like opening a browser tab), the operating system automatically assigns a temporary, randomly chosen port number from a reserved high-numbered range (typically 49152-65535) for that specific connection โ€” this is called an ephemeral port. It only needs to exist for the duration of that one conversation, and gets freed up afterward for reuse.

๐ŸŒ Real-World Use

When you open 5 tabs to the same website, your browser (and OS) assigns each tab a different ephemeral source port, even though all 5 are connecting to the same server IP and the same port 443 โ€” this is exactly how your device keeps each tab's data separate and correctly routed, even though they're visiting the identical destination.

๐Ÿ’ก Pro Tip

A commonly tested fact: a socket is defined by the FULL combination of (source IP, source port, destination IP, destination port) โ€” not just a port number alone. Memorizing this 4-part definition (sometimes called a 'socket pair') is exactly what most exam questions on this topic are checking for.

๐Ÿงช Quick Self-Test

Check what you just learned โ€” no pressure, just practice.

1. Which port is commonly used for HTTPS (secure web) traffic?

2. What combination defines a socket?

3. What is an ephemeral port?

โ† Back to all Notes