I wondered what is the origin of the decision to make localhost's IP address 127.0.0.1. What is the "meaning" of 127? what is the "meaning" of 0.0.1?
|
|
|||||||||||||||||||
|
|
127 is the last network number in a class A network with a subnet mask of |
|||||||||
|
|
Earliest mention I can find regarding 127's assignment as loopback is November 1986 RFC 990 authored by Reynolds and Postel:
Even as early as September 1981 RFC 790, 0 and 127 were already reserved: 000.rrr.rrr.rrr Reserved [JBP] ... 127.rrr.rrr.rrr Reserved [JBP] 0 and 127 were the only reserved Class A networks by 1981. 0 was used for pointing to a specific host, so that left 127 for loopback. I know this doesn't answer the question, but this is as far back as I could dig. It might have made more sense to choose 1.0.0.0 for loopback but that was already given to BBN Packet Radio Network. |
|||
|
|
|
The designers of the Internet really knew how the hardware worked, and they designed with low level implementation in mind. The values 0, 127 and 255 are special in 8 bit assembly and machine language programming because there are "tricks" you can use to test for these values and branch to different code using smaller instructions that execute faster than for other integers. 127 is the highest signed 8 bit integer, so incrementing it by 1 will cause a signed overflow. Similarly, incrementing 255 will cause unsigned overflow. Merely loading the value 0 into a register will usually set a zero flag on the chip. Imagine the networking program looks like this in pseudocode:
Although it depends on the chip, in those days most chips could encode these tests with 2 words, 3 words and 3 words respectively (total 8 words) and further those particular tests were all likely to execute in 1 clock cycle each. Using any other value would probably require 4 words each (total 12 words), a 50% increase in code size and likely a 50% increase in execution time as well. |
|||
|
|
If you think about what a localhost or loopback IP address means, you realize that you never want to see that address, or the network that that address belongs to, outside of a host. (Inside of a host, it's too dark to see it. Apologies to Mark Twain.) So, someone had to pick an IP network to represent this localhost address. I don't recall who first chose it, but it's specified in the IETF Request for Comments that is periodically issued as "Host Requirements". It was done so long ago, that the idea of "wasting" an entire class A address didn't enter anyone's mind at the time. The utility of localhost is that you can talk to yourself using a hard-coded IP address. It was used long before there was the Domain Name System. You could actually use any of the 127.x.x.x valid addresses, but no one ever does. You can't sneak and use 127 as a real network because the "Router Requirements" RFC disallows ever routing that network on any internet. |
|||
|
|
|
First, the whole 127.x.x.x range points to your localhost.
|
|||||||||
|