Why Is Localhost’s IP Address 127.0.0.1? How does It work?

We all know that 127.0.0.1 points to localhost. However, have you ever wondered why 127.0.0.1 IP Address is assigned to localhost?

Why Is Localhost’s IP Address 127.0.0.1? How does It work?

In the computer world, localhost refers to the location of the system being used. You also might be knowing that 127.0.0.1 points to localhost. However, have you ever wondered why localhost’s IP address is 127.0.0.1 why not something else?

The address 127.0.0.1 is used to establish a connection to the same computer used by the end-user. Below is the detailed answer by a user on Super User forum

“127 is the last network number in a class A network with a subnet mask of 255.0.0.0. 127.0.0.1 is the first assignable address in the subnet. 127.0.0.0 cannot be used because that would be the wire number. But using any other numbers for the host portion should work fine and revert to using127.0.0.1. You can try pinging 127.1.1.1 if you’d like. Why they waited until the last network number to implement this? I don’t think it’s documented.”

Actually, Developers practice 127.0.0.1 to test their applications before deploying it. This address is used to access the network services that are currently running on the host via its loopback network interface. That means, anything you send out to that IP address goes to your machine, the same machine that you’re sending from.

Now you might be thinking why localhost IP address starts with 127? Well, 127 is the last network number in a class A network with a subnet mask of 255.0.0.0. 127.0.0.1 is the first assignable address in the subnet. Therefore, any number from the host portion will work fine. You can try pinging 127.1.0.1, you will be looped back to your own machine.

You might be wondering why the last network number in a Class A network was chosen to implement this? Actually, the earliest mention of 127 as loopback dates back to November 1986 RFC 990. By the year 1981, 0 and 127 were the only reserved class A networks where 0 was used for pointing to a specific host and 127 was left for loopback.

Some might think that it could be more sensible to choose 1.0.0.0 for loopback. However, that was already given to BBC Packet Radio network.

You can find out more details on Superuser.com forum.



COMMENTS