In IPv4, what do 127.0.0.1, 0.0.0.0 and 255.255.255.255 each mean, and where may each appear in a packet?
answer
- inside the host, not yet configured, everyone here
- a whole /8, not one address
- source-only versus destination-only
- never crosses a router
basics
~20 s127.0.0.1 belongs to the 127.0.0.0/8 loopback block, which must never leave the host. 0.0.0.0 means "this host on this network", valid only as a source while a host learns its address. 255.255.255.255 is limited broadcast: destination only, never forwarded.
solid answer
~40 sAll three come from RFC 1122 Section 3.2.1.3. The **loopback** block is the whole `127.0.0.0/8`, not just `127.0.0.1`; addresses in it must not appear outside a host, and RFC 1812 says routers should not forward packets with a network-127 source or destination. `0.0.0.0` means **this host on this network**: it must not be sent except as a **source** address while a host is still learning its own address, which is why a host's first configuration request carries it. `255.255.255.255` is **limited broadcast**: it must not be used as a source, every host on the attached link receives it, and routers must not forward it. Two other uses of zeros are not wire addresses: binding a socket to 0.0.0.0 means "any local address" in the sockets API, and `0.0.0.0/0` is the default route.
go deeper
Know what each of the three addresses is for: talking to yourself, not having an address yet, and reaching everyone on the local link.
Explain the source and destination rules from RFC 1122, why routers must not forward any of them, and why a socket bound to 0.0.0.0 and the 0.0.0.0/0 route are different ideas.
Apply the rules defensively: filters must match the whole 127.0.0.0/8 and 0.0.0.0/8, not single addresses, and broadcast-based bootstrap traffic stops at the first router unless something relays it.
Treat these blocks as protocol invariants when reviewing designs: anything that relies on loopback traffic leaving a host, or broadcast crossing a router, is building on behaviour the standards forbid.
## Three addresses, three rules RFC 1122 (host requirements) lists the special forms of an IPv4 address in Section 3.2.1.3, and RFC 1812 (router requirements) repeats them from the router's side. Three of them come up constantly: | Address or block | Name | As a source | As a destination | Forwarded by routers? | |---|---|---|---|---| | `127.0.0.0/8` | Loopback | Must not appear outside the host | Must not appear outside the host | No | | `0.0.0.0/8` | This host on this network | Only while the host learns its address | Never | No | | `255.255.255.255` | Limited broadcast | Never | Yes, on the attached link | No | The IANA special-purpose registry (RFC 6890) records the same thing as booleans: `0.0.0.0/8` is valid as source but not destination; `127.0.0.0/8` is valid as neither, with footnoted exceptions for a few protocols; `255.255.255.255/32` is valid as destination only and is not forwardable. RFC 8190 later marked limited broadcast as reserved by protocol, aligning the registry with RFC 919. ## Loopback: the whole /8 `127.0.0.1` is the conventional loopback address, but RFC 1122 reserves **every** address of the form `{127, <any>}`: 127.0.0.0 through 127.255.255.255, about 16.7 million addresses. A packet sent to any of them is looped back inside the host's own stack and never reaches a network interface. - RFC 1122: loopback addresses **must not appear outside a host**. - RFC 1812 Section 5.3.7: a router **should not** forward, except over a loopback interface, any packet with a source or destination on network 127. - Practical consequence: a filter or check that matches only `127.0.0.1` misses `127.0.0.2` and the rest of the block, which a host will still loop back. ## "This network": 0.0.0.0 and its other meanings On the wire, an all-zeros address is a placeholder for an address the host does not have yet: 1. `{0, 0}`, written 0.0.0.0, is **this host on this network**. RFC 1122: it must not be sent, except as a **source** address during an initialisation procedure by which the host learns its own IP address. A host broadcasting its first configuration request, before any address is assigned, uses it this way. 2. `{0, <host>}` is **specified host on this network**, with the same source-only restriction. 3. Routers should not forward packets with a source or destination on network 0 (RFC 1812 Section 5.3.7). Zeros mean other things off the wire, and conflating them is a common error: - **A socket bound to 0.0.0.0** listens on every local address. That is a sockets-API convention, not a packet address. - **`0.0.0.0/0`** is a prefix of length zero: the default route, which matches every destination. That is routing-table notation. - **0.0.0.0 as a destination** is, per RFC 1812, an obsolete form of limited broadcast. Routers should silently discard such packets, and if they do not, must treat them like 255.255.255.255. - Some host stacks treat an outgoing connection to 0.0.0.0 as a connection to the local host; Linux is one example. That is implementation behaviour, and the reason destination filters must cover `0.0.0.0/8`. ## Limited broadcast `255.255.255.255` is the **limited broadcast** address, the `{-1, -1}` form in RFC 1122's notation: - it **must not** be used as a source address; - a datagram sent to it is received by every host on the connected physical network; - RFC 1812 Section 5.3.5.1: limited broadcasts **must not be forwarded**, and also **must not be discarded** by the router, which receives them like any host does. That makes it the address a host can use before it knows its own subnet: it needs no prefix length, and it can never leak beyond the link. By contrast a **directed broadcast** such as 192.0.2.255 for 192.0.2.0/24 names one specific subnet and is routed toward it. Directed broadcast belongs with address structure, not with this reserved catalogue. ## Why the rules point in different directions - Loopback is about **the host itself**, so it may not appear on any wire in either direction. - "This network" is about **a host that does not yet have an address**, so it can only describe a sender. - Limited broadcast is about **everyone on this link**, so it can only describe receivers and must stop at the first router. An IPv4 host's own source address must be one of its own unicast addresses, never a broadcast or multicast address (RFC 1122), which is why neither 255.255.255.255 nor a 224.0.0.0/4 group address can be a legitimate source.
- Is 127.0.0.1 the only IPv4 loopback address?No. RFC 1122 reserves every address of the form 127.x.y.z, the whole 127.0.0.0/8, as internal host loopback, and none of it may appear outside a host. 127.0.0.1 is just the conventional choice, so checks and filters must match the full /8.
- What should an IPv4 router do with a packet whose destination is 0.0.0.0?RFC 1812 calls 0.0.0.0 an obsolete form of the limited broadcast address. Such packets should be silently discarded; if a router does accept them, it must treat them by the same rules as 255.255.255.255, which means never forwarding them.
- Why may 0.0.0.0 appear as an IPv4 source address but never as a destination?It stands for "this host" when the host does not yet know its address. A host can truthfully send from that placeholder while it asks for configuration, but nobody can address a reply to it, so RFC 1122 allows it only as a source during initialisation and the registry marks it invalid as a destination.
Loopback is talking to yourself: nothing leaves your head. Limited broadcast is shouting in a closed room: everyone in the room hears it, and the walls (routers) stop it from going further.
saying these in an interview costs you the question
- Only 127.0.0.1 is loopback; the rest of 127.0.0.0/8 is ordinary unicast.
- 0.0.0.0 on the wire means every interface, as it does in a bind call.
- Routers forward 255.255.255.255 to every attached network.
- A host may send from 255.255.255.255 to reach everyone at once.
- Loopback traffic goes out to the gateway and comes back.