Port Numbers Explained

CertBrosCisco CCNA

In this video, we going to be looking at port numbers.

So, back to our trip through the TCP/IP model. And remember, we are going through these layers as if we’re were sending data, so top to bottom.

In the last video, we looked at the layer 4 protocols TCP and UDP. Layer 4 is also responsible for choosing port numbers. And that’s what we’re going to look at in a bit more detail.

Ok, so why do we need port numbers?

I like to think of port numbers like a letterbox. when the postman comes, your letters can be put through that letterbox. The letterbox gives the service (post) access to your house.

Computers work in the same way. The post in this example is the application data and the letterbox is the port number for that application. Port number provides applications access to a computer.

Instead of a house, it might be a server. Instead of post, the service might be a mail or web server.

Let’s say we want to access the webserver.

We type in the web address of the site we want to visit. The first thing the computer does it convert that URL to an IP address. This is done by using DNS, but we will cover than in another video. For now, just know it coverts web addresses to IP addresses.

The computer then sends the request to the webserver. But this server may not just be hosting a web site using HTTP, it may also be a mail server using SMTP, or even a file server using FTP.

Well-Known Port Numbers

How does the server know which application to send the request to?
Well, these applications have something called a well-known port number assigned to them.

  • HTTP is assigned port number 80
  • SMTP is assigned port number 25
  • FTP is assigned port number 20 / 21

Because the port numbers are standard numbers, all computers will know about them.

When we made our web request, our computer knew we were trying to access a HTTP site, so it added the destination port number 80 to the TCP header. The computer will also choose a randomly generated source port to receive reply’s on.

When the request is sent, it’s sent to the web servers IP address and the well-known port for that service. The IP address and port number are often written like below. It’s the IP address, a colon, then the destination port number.

The server will receive this request, look at the destination port number, realise that the request is for the web application and pass it to that application.

The server will then respond. This time, the ports are reversed. The dentation port is now the randomly generated one and the source port is now our well-known port 80.

Again, when we receive this response, our computer looks at the port number. This port number lets our computer know which application to send it to, in this case, our browser.

So the IP addresses get the data to the computer but it’s the port number that gets that data to the right application.

Now, this is a simplified version of how this works just to give you an idea about port numbers, what they’re used for, and how they work.

OK so, let’s look at well-known port numbers is some more detail.

There are several port numbers that are called well-known ports. These are common protocols that have been assigned port numbers. Here is a small list of some of the most common ones you’ll find.

Common Ports

Now, this is by no means a complete list. No, in fact, port numbers 0 – 1023 are well-known port numbers. Thankfully, we only really need to know the more commons ones.

There are also ports ranging from 1024 – 49151, these are registered ports that companies have registered IANA.

And finally, from 49152-65535 which are the dynamically assigned ports we saw as the source. These are used to randomly choose a unique port number for that local computer to use as its source.

Try at Home

So, to give you something to try at home, let’s see these ports in action.

If you were to open PowerShell on your Windows computer and type, netstat -n to show all current connections in numeric value.

Here’ what you’ll see.

  • Local address – your computers’ address.
    Note that it shows a colon and a port number. It this case, it’s our source port
  • Foreign address – This is the IP address of the device you are connected to.
    This also has the port number. Here it’s our destination and well-known port number of 80.

So that’s it for the Port numbers.

Go look at your own connection and the port numbers being used.

Follow us