
libp2p is the peer-to-peer networking layer IPFS runs on. It gives every node a verifiable identity, encrypts and multiplexes its connections, and gets peers through NATs, so the DHT and Bitswap have a connection to run over.
TL;DR:
/ip4/198.51.100.7/udp/4001/quic-v1/p2p/<PeerID>Updated Oct 29, 2026: added a step-by-step NAT traversal section (AutoNAT, Circuit Relay v2 reservations and limits, DCUtR hole punching and its measured success rate), corrected the Noise, TLS and mplex details against the current Kubo docs, and added a labelled diagram.
libp2p is a modular networking stack: a set of protocols, specifications and libraries for peer-to-peer communication. It began as the wire protocol of the IPFS project and later grew into a standalone framework that many other projects use. The IPFS team describes the split this way: IPFS focuses on content addressing, while libp2p focuses on process addressing.
In practice, that means IPFS asks "which blocks make up this CID?" and libp2p answers "how do I reach the peer that has them?" You need both. A CID tells you what to fetch, but it says nothing about where the provider sits on the network or whether you can even open a connection to it.
libp2p ships its pieces as swappable modules instead of one fixed protocol. Transports, security protocols, stream multiplexers, peer discovery and NAT traversal are all separate parts. An application such as Kubo picks the ones it needs, which is why one IPFS node can talk TCP to one peer and QUIC to another.
The DHT lookups and Bitswap block exchanges that move IPFS content both assume a connection already exists. A DHT query and a Bitswap want-have message each travel as a libp2p stream over a libp2p connection. If you strip libp2p out, neither protocol has anything to run on.
The same holds for the push-based messaging in GossipSub, the PubSub protocol IPFS uses. It is one more protocol that rides on the connections libp2p sets up. That is why this page is the networking pillar for the whole picture of how IPFS stores and routes data.
A libp2p Peer ID is not handed out by a registry. It is derived from the peer's own public key, so you can check a peer's claim to an ID against the key it signs with. This is the same logic as a CID applied to identity: the identifier proves itself through cryptography rather than through an authority.
Addresses work the same self-describing way. A multiaddr such as /ip4/198.51.100.7/tcp/4001/p2p/<PeerID> reads left to right as a stack: IPv4 at this address, TCP on this port, and this peer at the end. One peer can advertise several multiaddrs at once, for example TCP and QUIC, and your node can try any of them without the format changing. A new node starts from multiaddrs too. Kubo's Bootstrap setting lists the multiaddrs of trusted peers your node dials first, which is how IPFS bootstrap nodes give a new node its first peers.
Once your node has an address, libp2p negotiates a security protocol before any application data flows. On TCP, Kubo supports TLS 1.3 and Noise. Its config docs list TLS at priority 100 and Noise at 200, and lower values win when Kubo dials out. The libp2p docs describe Noise as the framework that encrypts traffic between nodes and provides forward secrecy.
After the handshake, a stream multiplexer lets one connection carry many independent streams. That way a DHT lookup and a Bitswap exchange with the same peer share a single connection. Yamux is the multiplexer Kubo uses, and its flow control through backpressure stops one busy stream from flooding the others.
The older mplex multiplexer had no stream-level backpressure, and Kubo's docs now say support for it has been removed from Kubo and go-libp2p. QUIC is a special case: it has encryption and stream multiplexing built in, so the separate security and multiplexer steps don't apply to QUIC connections. The differences between TCP and QUIC as IPFS transports are covered in their own post.

Most home and office machines, and nearly all phones, sit behind a NAT or firewall. They can dial out to public peers, but nobody on the public internet can dial in to them. UPnP and manual port forwarding can open a port, yet routers often disable UPnP, and port forwarding takes manual work on every network.
libp2p solves this with a decentralized version of the ICE approach, without central STUN or TURN servers. The libp2p hole punching guide splits it into a preparation phase and a hole punching phase. Here is the full sequence when your node is behind a NAT.
Your node first needs to know whether it is public at all. AutoNAT lets it ask other peers to dial back the addresses it thinks are public. If most dial-backs succeed, the node is reachable; if most fail, a NAT is blocking inbound connections.
The libp2p docs say a node behind a NAT should stop advertising its private addresses and get a relay reservation instead. This is the role STUN plays in classic NAT traversal. AutoNAT also refuses dial requests that arrive over relayed connections, which prevents amplification attacks.
Next, your node finds public peers willing to relay and asks one for a reservation. In IPFS, any public node can act as a relay. Once the relay accepts, your node advertises a relay address such as /ip4/198.51.100.0/tcp/55555/p2p/QmRelay/p2p-circuit/p2p/QmAlice, where everything before /p2p-circuit/ points to the relay.
Circuit Relay v2 is built to stay cheap for the relay. Kubo's defaults reset a relayed connection after 2 minutes or 128 KiB of data in each direction, keep a reservation for 1 hour, and allow 128 reservations per relay. The relay can't read your traffic, because relayed connections are end-to-end encrypted. They are not anonymous, though: every participant, the relay included, is identified by its Peer ID.
When another peer wants to reach you, it first connects through your relay. Over that relayed connection, the two peers run DCUtR (Direct Connection Upgrade through Relay), protocol ID /libp2p/dcutr. They exchange Connect messages that list each side's non-relayed addresses, and the initiator measures the round-trip time between them.
The initiator then sends a Sync message and both peers dial each other at the same moment. Each outgoing packet opens a mapping in its own router's state table, so the packet arriving from the other side matches it and gets through. That simultaneous dial is the "hole punch", and DCUtR supports it for both TCP and QUIC.
Hole punching doesn't always work. A 2025 measurement study of DCUtR in the production IPFS network drew on over 4.4 million traversal attempts from more than 85,000 networks in 167 countries. It found a success rate of 70% plus or minus 7.1%, about the same for TCP and QUIC, and 97.6% of successful connections succeeded on the first attempt.
For the remaining cases, the relayed connection is all you get, with the time and data limits from Step 2. That is fine for a short DHT exchange but not for moving large files.
Each one covers the other's weakness. A relay works almost every time, but it adds latency and costs the relay operator bandwidth, so v2 relays cap what they carry. A hole punch gives you a fast direct connection, but the two peers must coordinate a simultaneous dial, and they have no channel to coordinate over until the relay provides one.
So the relay comes first and makes the connection possible, and DCUtR then tries to remove the relay from the path. If you have used WebRTC, the pattern will look familiar: AutoNAT plays the STUN role and Circuit Relay plays the TURN role. The difference is that libp2p spreads both roles across ordinary public peers instead of running central servers.
If you run Kubo, the relevant switches are in the Swarm section of the config. Per the Kubo config docs, Swarm.RelayClient.Enabled defaults to true, so your node uses public relays when it detects it is unreachable. Swarm.EnableHolePunching also defaults to true and needs the relay client enabled to work. Swarm.RelayService.Enabled controls whether your node acts as a relay for others.
These commands come from the Kubo docs and were not run here, since this machine has no IPFS binary:
# Not run: read the NAT traversal switches on a Kubo node
ipfs config Swarm.RelayClient.Enabled
ipfs config Swarm.EnableHolePunching
ipfs config Swarm.RelayService.Enabled
To see the result from the outside, the IPFS Check web tool reports which multiaddr it used to reach a provider. If one of the successful addresses contains p2p-circuit, retrieval from that peer needed NAT traversal. A swarm key adds one more gate at this layer, as the post on IPFS private networks and swarm keys explains.
When you fetch content through an AIOZ Pin gateway, your client never touches libp2p. The AIOZ Pin docs describe gateways as the bridge that lets browsers and apps request IPFS content over plain HTTP, using the format https://gateway-url/ipfs/<CID>. Peer IDs, security handshakes and NAT traversal stay on the gateway's side of the request.
The docs also say content pinned on AIOZ Pin becomes available on the public IPFS network, so anyone running an IPFS node can fetch it through their own node. That path does use everything above. Premium gateways add what the docs call a global network of 200+ edge-caching locations. The docs don't describe how AIOZ Pin's own nodes configure relays or hole punching.
# Not run: the gateway URL format from the AIOZ Pin docs, as a plain HTTP request
curl "https://<gateway-url>/ipfs/<CID>" -o file
Next step: read the AIOZ Pin guide to gateways and how gateway URLs are built.
What is libp2p in IPFS? It is the networking framework IPFS runs on. It handles peer identity, connection security, stream multiplexing and NAT traversal, and the DHT and Bitswap run on top of it.
Is libp2p only used by IPFS? No. It started as IPFS's wire protocol and became a standalone, modular stack that other peer-to-peer projects use as well.
What is the difference between Circuit Relay v1 and v2? The libp2p docs recommend v2. It requires reservations and lets relays limit the number, duration and data volume of relayed connections, so most public peers can relay without much cost.
What is DCUtR? Direct Connection Upgrade through Relay. Two peers connected through a relay exchange addresses and measure the round-trip time, then dial each other at the same moment to open a direct connection through their NATs.
How often does libp2p hole punching work? A 2025 study of more than 4.4 million attempts in the IPFS network measured a 70% success rate, with TCP and QUIC performing about the same.
Does Kubo still support mplex? No. Kubo's config docs say mplex support has been removed from Kubo and go-libp2p, and Yamux is the multiplexer Kubo uses.
Do AIOZ Pin's gateways use libp2p? Your request to a gateway is plain HTTP. Content pinned on AIOZ Pin is also available on the public IPFS network, where IPFS nodes fetch it over libp2p.

A multiaddr is a network address that names every protocol it uses, like /ip4/.../tcp/4001/p2p/ and a peer ID. Learn to read one and how IPFS peer IDs work.

IPFS bootstrap nodes are the first peers a new node dials to join the Amino DHT. See how Kubo uses them, who runs them after Shipyard, and how to edit the list.

The ipfs.io gateway now returns HTTP 429 to scripts and servers and sends browsers to inbrowser.link. See who runs the public IPFS services and what to change.

An IPFS glossary of 115 terms from A to Z: CIDs, Bitswap, the DHT, IPNS, gateways and pinning, each defined in plain words and linked to a deeper guide.

IPFS Provide Sweep is Kubo's provider that batches CIDs by DHT region, not one lookup each. See how it works, when it became default, and how to check it.

An IPFS dedicated gateway on AIOZ Pin is called a premium gateway. See what the free plan limits, what a paid plan adds, and what happens at zero balance.