Networking & Sockets

IP, the IP address, a host, and a port

/ IP -> EYE-PEE /

To deliver mail to one person, you need two things: the building's street address, and the apartment number inside it. On a network the building is the machine, found by its IP address, and the apartment is the particular program on that machine, found by its port number. The Internet Protocol (IP) is the rulebook for addressing and routing packets between machines; the IP address is the machine's number under that rulebook.

An IP address identifies a host - any machine reachable on the network. The older form, IPv4, is four numbers 0 to 255 such as 93.184.216.34 (32 bits, about 4 billion possible addresses, now nearly exhausted). The newer form, IPv6, is eight groups of hex digits such as 2606:2800:220:1:248:1893:25c8:1946 (128 bits, effectively unlimited). The IP address gets a packet to the right machine. But a machine runs many programs at once - a web server, a mail server, an ssh server - so a packet also carries a port number (0 to 65535) saying which program it is for. The pair (IP address, port) names one specific endpoint you can talk to.

Why it matters: every connection you make is fundamentally 'this IP, this port'. When you write a server you choose a port to listen on; when you write a client you must know the server's IP and port. Confusing the two is a classic beginner error: the IP gets you to the right computer, the port gets you to the right program on it. A host can have several IP addresses, and one IP can host thousands of ports at once.

In the address 93.184.216.34:443 the part before the colon (93.184.216.34) is the IP address picking the machine; the part after (443) is the port picking the program, here a secure web server. The combination names exactly one place to send bytes.

IP address = which machine; port = which program on it. Together they name one endpoint.

An IP address is not the same as a domain name. example.com is a human-friendly name that must first be looked up (via DNS) to find its IP address; the network itself routes only by IP, never by name.

Also called
Internet ProtocolIPv4 and IPv6網際網路協定主機與連接埠