In computing, the term localhost refers to the location of the system being used. It is a device loopback to which is assigned the IP address 127.0.0.1 in IPv4 or in IPv6 and can be used by applications TCP / IP to test communication with themselves.
Being able to communicate with the current machine as if it were communicating with a remote machine is useful for the purpose of testing, and to use resources located on the current machine, but that would be expected to be remote.
Have You ever imagined why is localhost’s IP Address 127.0.0.1 why not something else? Usually, Developers use 127.0.0.1 to test their applications. Whenever you try to establish a loopback network connection, Localhost always translates to the loopback IP address 127.0.0.1 in IPv4, or in IPv6.
Now You might be asking why Localhost IP Address always starts with 127? Well, 127 is there for a reason. Actually, 127 is the last network number in a class A network with a subnet mask of 255.0.0.0. This means that if you try to connect to 127.0.0.1, you are immediately looped back to your own machine.
You can use any other numbers for the host portion that will revert to 127.0.0.1. You can try pinging 127.1.1.1. You might also ask why the last network number was chosen to implement this. Well, the earliest mention of 127 as loopback dates back to November 1986 RFC 990. And, by 1981, 0 and 127 were the only reserved Class A networks.
As Mentioned in Howtogeek “The class A network number 127 is assigned the “loopback” function, that is, a datagram sent by a higher level protocol to a network 127 address should loop back inside the host. No datagram “sent” to a network 127 address should ever appear on any network anywhere.”
As we already mentioned in the year 1981, 0 and 127 were the only reserved Class A network in which 0 Was used for pointing to a specific host and that left 127. Therefore, all developers have to use 127 for loopback. It is worth to think that it will be more sensible to choose 188.8.131.52 for loopback. However, it was already given to BBC Packet Radio Network.
You can find more details at Superuser