When you access an IP address, you usually want to connect to another computer on the internet. However, when you use the IP address 127.0.0.1, you’re com­mu­ni­cat­ing with the localhost — es­sen­tial­ly, your own computer. But why would you want to have a “virtual con­ver­sa­tion” with yourself? What do you need the localhost for, and how does this loopback work?

$1 Domain Names – Grab your favorite one
  • Simple reg­is­tra­tion
  • Premium TLDs at great prices
  • 24/7 personal con­sul­tant included
  • Free privacy pro­tec­tion for eligible domains

What exactly is the localhost?

The easiest way to describe the localhost is that it refers to your own computer — when you access it, your device is es­sen­tial­ly com­mu­ni­cat­ing with itself. However, this is only a sim­pli­fied ex­pla­na­tion. The localhost isn’t directly connected to your physical PC. In most home networks, your computer has a local IP address such as 192.168.0.1. The address used on the internet, however, is different and usually assigned dy­nam­i­cal­ly by your internet provider. The term localhost comes into play when a server is running on your own computer.

This means, con­verse­ly, that the term “localhost” is only used in the context of networks. It doesn’t just refer to the virtual server itself but also to its domain name. Just like .test, .example, or .invalid, .localhost is a top-level domain reserved for doc­u­men­ta­tion and testing purposes. When you try to access this domain, a loopback process is triggered. So if you enter http://localhost in your browser, the request isn’t sent through your router to the internet — it stays within your own system. The localhost has the IP address 127.0.0.1, which points to the server running on your own computer.

Image: Localhost (127.0.0.1)
Diagram showing localhost com­mu­ni­ca­tion

How loopback works (127.0.0.1)

IP addresses are used within a network to enable com­mu­ni­ca­tion among par­tic­i­pants. Each par­tic­i­pant in the network has their own address. Data packets sent via TCP/IP reach the correct des­ti­na­tion because of this system. The protocol pair Trans­mis­sion Control Protocol (TCP) and Internet Protocol (IP) forms one of the cor­ner­stones of the internet. However, TCP/IP is also used in local networks beyond the internet. The Internet Protocol is re­spon­si­ble for ensuring that par­tic­i­pants in a network can be addressed using an IP address and a subnet mask.

Note

Public IP addresses — those that can be accessed over the internet — are assigned and regulated by the Internet Cor­po­ra­tion for Assigned Names and Numbers (ICANN). This or­ga­ni­za­tion also oversees the Domain Name System (DNS), which manages the al­lo­ca­tion of domain names. However, some IP address ranges are reserved for specific purposes, such as the block from 127.0.0.0 to 127.255.255.255.

Until the 1990s, IP addresses on the internet were cat­e­go­rized into different classes. Class A began with 0.0.0.0 (also a reserved address) and extended up to 127.255.255.255. This makes 127 the final block within the Class A range — a prominent position that may have in­flu­enced its selection.

Within this address range, you can set up a localnet. What makes this range special is not only that it’s reserved by ICANN, but also that the IP addresses within it are not uniquely assigned, unlike most others. Here’s how it works: normally, when you enter an IP address or domain name in your browser, your router forwards the request to the internet and to the ap­pro­pri­ate server. But with 127.0.0.1, things work dif­fer­ent­ly — requests to this address never leave your computer. The TCP/IP protocol rec­og­nizes from the first block (127) that the address refers back to your own system. As a result, the loopback process is initiated.

Fact

Under IPv6, the address ::1 is reserved for loopback.

To ensure the backward reference to the local machine works, a loopback device is created. This refers to a virtual interface. It is fully im­ple­ment­ed through the operating system. On Unix systems, the interface is called “lo” or “lo0”. These can also be displayed here using the ifconfig command. A com­pa­ra­ble command in Windows is ipconfig.

Fact

When con­sid­er­ing the tech­nol­o­gy sep­a­rate­ly from the localhost, a loopback can also be realized anal­o­gous­ly: Through circuits in com­mu­ni­ca­tion tech­nol­o­gy, it can be de­ter­mined whether both the path the signal takes and the reception are correct.

What is localhost used for?

De­vel­op­ers use the localhost when testing programs and web ap­pli­ca­tions. Similarly, network ad­min­is­tra­tors can utilize the loopback for testing network con­nec­tions. Another practical use for localhost is in the hosts file, where the loopback can be used to block harmful websites.

Note

In modern cloud-based de­vel­op­ment en­vi­ron­ments, working with local servers is now rare. Instead, virtual machines or con­tain­ers are used, which operate in the cloud. In such cases, the tra­di­tion­al use of localhost (127.0.0.1) for sim­u­lat­ing network con­nec­tions may be less relevant.

Testing purposes

Localhost is mainly used when working with web servers or de­vel­op­ing ap­pli­ca­tions that need internet-style com­mu­ni­ca­tion. During de­vel­op­ment, it’s crucial to test whether an ap­pli­ca­tion works correctly when accessed as it would be online. Some functions only run properly when the cor­re­spond­ing files are available on a simulated or “pseudo” internet. For example, there’s a dif­fer­ence between simply opening an HTML file on your computer and uploading it to a server to view it in a browser. Of course, releasing an un­fin­ished product publicly isn’t a good idea — and that’s where the loopback comes in. De­vel­op­ers use it to simulate a network con­nec­tion while keeping all data traffic local. In other words, the con­nec­tion stays entirely within their own system.

Another advantage of using it for testing purposes is speed. Sending a request over the internet can take over 100 mil­lisec­onds. However, if you ping the localhost, the trans­mis­sion should take at most one mil­lisec­ond. This technique can also reveal if the internet protocol is im­ple­ment­ed correctly. To test this yourself, simply open the command prompt (Windows) or terminal (Unix/Mac) and use the ping command. You can send it either to the domain “localhost” or directly to the IP address:

ping localhost
ping 127.0.0.1
bash

If you want to set up your own test server on your PC to access it via localhost, you need to install the ap­pro­pri­ate software. Generally, it is possible to run any standard web server on your own computer. However, there are also specific ap­pli­ca­tions designed specif­i­cal­ly for use as localhost. One such example is the software stack XAMPP.

Be secure. Buy an SSL cer­tifi­cate.
  • Secures data transfers
  • Avoids browser warnings
  • Improves your Google ranking

Blocking websites

Localhost also plays an important role in the hosts file. This file can be con­sid­ered a pre­de­ces­sor of the Domain Name System (DNS): it allows IP addresses to be linked to their cor­re­spond­ing domain names. When you enter a website address in your browser, the domain must be trans­lat­ed into an IP address. In the past, this was done using the hosts file. Today, however, this task is usually handled by the global DNS. Still, the hosts file is present in most operating systems. On Windows, you can find it under \system32\drivers\etc\hosts, and on macOS or other Unix-based systems under /etc/hosts.

If you haven’t made any changes to the file yourself, you’ll probably find only two entries there:

127.0.0.1	localhost
::1			localhost
txt

This ensures that name res­o­lu­tion for localhost doesn’t have to go through the internet. However, you can also use the file to block specific websites. To do this, add the website you want to block to the list and assign the domain the IP address 127.0.0.1. If you — or, for example, a malicious script — try to access the blocked domain, the browser will first check the hosts file, find the entry, and stop the con­nec­tion there. Another option is to use the IP address 0.0.0.0.

The browser then tries to access the cor­re­spond­ing document (the website) on the server at 127.0.0.1. In most cases, it won’t find it, since the requested file doesn’t exist there. However, if you’ve set up your own test server, the browser might locate a home.html file — which would be your own local file. If no test server is running, an error message will appear instead of the requested website. This technique can also be used to block ad­ver­tise­ments across your entire system. To avoid adding each entry manually, you can find ready-made and regularly updated hosts files online.

Note

The hosts file can have a sig­nif­i­cant impact on your online security. While it’s a useful tool for blocking malicious websites, cy­ber­crim­i­nals can also exploit it by adding harmful entries. For this reason, you should be cautious not to import entries from un­ver­i­fied sources and ensure that no malware makes changes to the file without your knowledge.

Go to Main Menu