Loopback address

Also known as: localhost

On this page 7

A loopback address is a reserved IP address that always refers to the local host itself, so any packet sent to it is delivered back to the same machine without ever leaving through a physical network interface. In Internet addressing, the loopback block for IPv4 is 127.0.0.0/8, with 127.0.0.1 as the conventional address, while IPv6 defines a single loopback address, ::1. The hostname localhost is the standard name that resolves to these addresses.

Loopback addressing lets software talk to other software on the same computer through the full TCP/IP stack, exactly as it would across the Internet. Developers, system administrators and network engineers rely on it for testing, local services and diagnostics, and the concept underpins how operating systems separate internal communication from external traffic.

How a loopback address keeps traffic inside the host

A loopback address works because the operating system routes it to a virtual loopback interface instead of a network card. On Linux this interface is usually called lo, on macOS lo0, and Windows implements an equivalent internal adapter. When an application sends a packet to 127.0.0.1, the IP layer recognizes the destination, hands the packet to the loopback driver, and the driver immediately injects it back into the receive path of the same stack.

Because no hardware is involved, loopback traffic is not subject to physical link speed, cabling faults or switch configuration. Throughput is limited mainly by CPU and memory bandwidth, so local transfers often reach many gigabits per second. The packets still pass through routing tables, firewall rules and socket buffers, which is why loopback is a realistic test of the software path while remaining isolated from the wire.

The following table summarizes the components that participate when a packet is sent to a loopback destination.

ComponentRole in loopback deliveryTypical name or setting
Loopback interfaceVirtual device that returns packets to the stacklo, lo0
Routing table entryDirects the loopback range to the virtual interface127.0.0.0/8 dev lo
Name resolutionMaps the name localhost to the addresseshosts file entry
Firewall rulesMay filter or allow local trafficAccept on lo by default
Socket layerDelivers data to the listening applicationBound port on 127.0.0.1
Components in the loopback path

Reserved loopback ranges in IPv4 and IPv6

The loopback ranges are fixed by Internet standards, so every compliant host treats them identically. RFC 1122 requires that IPv4 addresses in 127.0.0.0/8 never appear on a network outside a host, and RFC 4291 defines ::1 as the IPv6 loopback address. The IANA special-purpose address registries list both blocks as not forwardable and not globally reachable.

A notable difference is scale. IPv4 dedicates an entire /8 block of about 16.7 million addresses to loopback, a decision from the early days of addressing that many engineers now regard as wasteful given IPv4 address exhaustion. IPv6 uses exactly one address, which reflects a more economical design. Linux answers on the whole 127.0.0.0/8 range by default, while some other systems configure only 127.0.0.1 unless further addresses are added.

PropertyIPv4IPv6
Reserved range127.0.0.0/8::1/128
Conventional address127.0.0.1::1
Number of addressesAbout 16.7 millionOne
Defining specificationRFC 1122RFC 4291
Forwardable by routersNoNo
Loopback definitions by protocol version

The localhost name has its own rules. RFC 6761 reserves localhost as a special-use domain name, and current guidance recommends that resolvers answer it locally with loopback addresses rather than forwarding queries to DNS servers. On a dual stack host, localhost may resolve to both ::1 and 127.0.0.1, and the order matters for which socket an application tries first.

A loopback address differs from other special addresses because it never identifies a network interface reachable by other hosts. Private IP addresses are routable inside an organization, and the unspecified address means no particular address at all. Confusing these categories is a frequent source of configuration errors, especially when deciding where a service should listen.

Address typeExampleReachable fromMain purpose
Loopback127.0.0.1, ::1Same host onlyLocal communication and testing
Unspecified0.0.0.0, ::Not a destinationBind to all interfaces
Private IP192.168.1.10Local networkInternal addressing behind NAT
Link-local169.254.x.x, fe80::/10Same network segmentAutomatic addressing without a server
Public IP203.0.113.5Entire InternetGlobal reachability
How loopback compares with neighboring address categories

The most practical distinction is between binding to 127.0.0.1 and binding to 0.0.0.0. A service bound to the loopback address accepts connections only from programs on the same machine, while a service bound to the unspecified address listens on every interface, including those facing the network. Choosing the wrong one can expose an administrative service to the outside world or, conversely, make a public service unreachable.

Practical uses of the loopback address

Loopback addressing is used wherever two programs on one host need to communicate through standard network APIs. The approach keeps code identical between local and remote deployments, because an application only changes the destination address. The table below lists common scenarios and the reason loopback suits each one.

ScenarioHow loopback is usedBenefit
Web developmentLocal server at localhost port 8080Testing without public exposure
Database accessDatabase listens on 127.0.0.1 onlyBlocks remote connection attempts
Stack diagnosticsping 127.0.0.1 or ping ::1Confirms TCP/IP stack is working
Reverse proxiesApplication server behind a local proxyOnly the proxy faces the network
Router managementLoopback interface on a routerStable address independent of links
Typical loopback use cases

On routers and network devices, the term has an additional, related meaning. Engineers configure a loopback interface with a routable address, often a /32 in IPv4, to give the device a stable identity that remains reachable as long as any physical link is up. Routing protocols such as OSPF and BGP commonly use this address as a router ID or session endpoint. Unlike 127.0.0.1, such an address is deliberately advertised to other routers.

Limitations, security considerations and common mistakes

Loopback is not an absolute security boundary. Any process on the host, including malware or another user account, can connect to a service listening on 127.0.0.1. Local services therefore still need authentication and access control, particularly on shared servers and developer workstations.

Browsers add another dimension. Attacks such as DNS rebinding can trick a web page into sending requests to services on localhost, which is why modern browsers increasingly restrict public websites from reaching private and loopback addresses. Containers create a separate subtlety: inside a container, 127.0.0.1 refers to the container itself, not to the host machine running it.

  • Assuming that localhost always means IPv4, which fails when it resolves to ::1 first and the service listens only on 127.0.0.1.
  • Leaving a database bound to 0.0.0.0 when it was meant to accept local connections only.
  • Expecting a containerized application to reach a host service through 127.0.0.1 without extra network configuration.
  • Writing firewall rules that accidentally block the loopback interface, which breaks many local services at once.

In everyday language

A loopback address is like sending a letter to yourself using your own home address. The letter never goes to the post office; it simply appears back in your own mailbox. Computers use the address 127.0.0.1, or the name localhost, in the same way to talk to themselves.

This is useful because programs on one computer often need to exchange information as if they were on a network. With loopback, they can do that safely and quickly, without anyone outside being able to listen in on the network.

Seen in the real world

A web developer building an online booking system runs the application server, a PostgreSQL database and a caching service on a single laptop. The application connects to the database at 127.0.0.1 on port 5432 and to the cache on 127.0.0.1 port 6379, while the developer opens localhost port 3000 in a browser to test the interface.

When the team later deploys to a production server, the same configuration pattern keeps the database and cache bound to the loopback address, so only the application on that server can reach them. A reverse proxy listens on the public interface and forwards requests internally. A routine security scan from outside finds only the proxy ports open, confirming that the internal services are invisible to the Internet.