Skip to content

Distributed Hash Table (DHT)

How IPFS nodes find each other and discover who has the content you're looking for.

What is a DHT?

A Distributed Hash Table is a decentralized lookup system. Think of it as a phone book that no single person holds — instead, each participant holds a few pages, and they know who to ask for the pages they don't have.

In IPFS, the DHT maps CIDs to the network addresses of nodes that have the corresponding content. When you request a file by CID, the DHT helps you find which nodes can serve it.

How it works in IPFS

IPFS uses a variant of the Kademlia DHT. Each node maintains a routing table of nearby nodes (in terms of XOR distance between node IDs). When a node wants to find content:

  1. It computes the XOR distance between the CID and known node IDs
  2. It asks the closest nodes it knows: "who has this CID?"
  3. Those nodes either have the content or point to nodes that are closer
  4. The search converges — each hop gets closer to a node that has the file
  5. The content is fetched directly from the providing node

TIP

This lookup typically takes only a few hops — even in a network of millions of nodes, a file can be located in 20-30 steps.

Provider records

When a node pins content, it publishes a provider record to the DHT announcing: "I have CID X, and my address is Y." These records expire after ~24 hours and must be refreshed periodically. This is why active pinning matters — without it, provider records expire and the content becomes undiscoverable.

Why you don't need to think about the DHT

IPFS.NINJA handles all DHT interactions for you. When you upload a file:

  • Our cluster pins the file and publishes provider records automatically
  • Provider records are refreshed continuously — your content stays discoverable
  • Our gateway resolves CIDs via the DHT when serving requests
  • You just use CIDs and gateway URLs — the DHT is invisible