IP addresses and ports — the basics

The two numbers that pin down exactly where a request goes — a specific machine on the network, and a specific program listening on that machine.

Beginner

3 min read

An IP address identifies a machine on a network

93.184.216.34                              (IPv4)
2606:2800:220:1:248:1893:25c8:1946          (IPv6)

An IP address identifies a specific device on a network — the way a street address identifies a specific building. IPv4 addresses (the familiar four-number format) are the older standard, and there are only about 4.3 billion possible IPv4 addresses — genuinely not enough for every device on the modern internet, which is the entire reason IPv6 exists: a vastly larger address space (2^128 possible addresses, effectively inexhaustible), gradually being adopted alongside IPv4 rather than replacing it outright.

A port identifies a specific program on that machine

A single machine can run many different network programs at once — a web server, a database, an SSH server for remote administration — all reachable at the same IP address, but distinguished by port, a number from 0 to 65535 identifying which specific program on that machine a connection is for. An IP address alone gets a request to the right machine; the port gets it to the right program running on that machine. This is why a full address in this context is usually written as IP:PORT — both pieces are needed to fully specify where a connection is actually going.

The well-known ports you'll see constantly

PortProtocolPurpose
80HTTPUnencrypted web traffic
443HTTPSEncrypted web traffic
22SSHRemote command-line access
5432PostgreSQLDatabase (default)
3306MySQLDatabase (default)
6379RedisCache (default)

Ports below 1024 are conventionally reserved for well-known, standard services — this is convention and common practice, not a hard technical law, but it's followed consistently enough that seeing :443 in a URL or log immediately tells you "this is HTTPS traffic" without needing to check anything else. This is also why a plain https://example.com URL doesn't need to mention a port explicitly at all — the browser already knows HTTPS means port 443 unless told otherwise.

Why localhost:3000 looks the way it does

http://localhost:3000

localhost is a special hostname that always refers to "this same machine" — the one the request originated from — commonly used during local development, where a server is running on your own computer rather than somewhere out on the network. :3000 (or :8000, :5000, and other common development ports) specifies which locally-running program to connect to, exactly the same way :443 specifies HTTPS on a remote server — running a development server on a non-standard port like 3000 is simply a convention that avoids colliding with a real production web server, which would typically claim the standard port 80/443 on the same machine if one happened to be running there too.

Where this connects to load balancing and scaling

A load balancer, covered in its own lesson, is itself just a program listening on a specific IP and port (commonly :443, since it's usually the first thing a client actually connects to) — it accepts the connection, then forwards the request to one of several backend servers, each running on their own IP:port combination, entirely invisible to the original client. Understanding IP:port as "exactly which program, on exactly which machine" is what makes that whole picture — a request travels through DNS, to a load balancer's IP:port, then internally to a backend server's own IP:port — concrete instead of abstract.

Further reading

Check your understanding

A quick comprehension check — not tracked, not graded, just for you.

1. What does an IP address identify, versus what a port identifies?

2. Why does IPv6 exist when IPv4 was already the standard?

3. Why does a plain https://example.com URL not need to mention a port?

4. What does :3000 in `http://localhost:3000` actually specify?