eli5: why so many ports?

139 views

“TCP also introduces a concept of a port: each connection has two ports, one for both sides. A port is an integer between 0 and 65535. A server typically waits for a new connection at a well-known port. Default ports for widely-used protocols are well-established and are typically small numbers, for example, HTTP uses port 80. A client also needs its own port. These ports are typically large numbers selected automatically by an operating system, based on what ports are available.”

Why is there a need for so many ports if there is just a client and a server? If there were multiple clients I assume the port number would need to be significantly big, but 65535 is relatively small.

In: 7

6 Answers

Anonymous 0 Comments

Imagine you have two families. The people in those families want to exchange letters with each other. The IP address is like the family name/last name. The Port is like the first name/personal name. A connection is letters sent back and forth between two individuals, identified by their first/last name.

Each service protocol on the server is assigned a port. HTTP communicates on port 80, HTTPS on 443, SSH uses 22, IMAP uses 143, etc. Just like each person in your family is assigned a name.

Why so many ports? Because when the protocol was designed there was no way to know how many different types of services would be offered. Why 65,536? Because computers like to operate using bits (1’s and 0’s) and bytes (8 digit binary numbers). 2 bytes or 16 bits allows you to represent up to 65,536 individual values. Going down to 1 byte or 8 bits would have limited it to only 256. And going all the way up to 4 bytes, well that would have been 4,294,967,295 values. 2 bytes is a pretty good compromise between too few and too many values.

Keep in mind, multiple different clients can talk to the same server using the same port. A port is just a number thats part of the address, its not, despite its name like a USB port or an audio port where you can only plug in one thing at a time. A TCP connection is defined using both the client and server IP and port numbers, so two different clients create two different connections, even though they share the same server IP and port. Just like one person can send and receive letters from multiple people, even at the same time.

You are viewing 1 out of 6 answers, click here to view all answers.