# How IPFS locates a specific file?

**URL:** <https://discuss.ipfs.tech/t/how-ipfs-locates-a-specific-file/3946>\
**Category:** Help\
**Created:** [September 27, 2018, 3:17am UTC](https://discuss.ipfs.tech/t/how-ipfs-locates-a-specific-file/3946 "2018-09-27T03:17:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![LastExile16](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/lastexile16/32/1353_2.png) [@LastExile16](https://discuss.ipfs.tech/u/LastExile16)\
**Post date:** [September 27, 2018, 3:17am UTC](https://discuss.ipfs.tech/t/how-ipfs-locates-a-specific-file/3946/1 "2018-09-27T03:17:19Z")

</div>

In IPFS each peer randomly stores and shares any file that results in any hash. That means, the file is not distributed according to some mechanism, rather it’s random.  
That file hash is used to identify the file over the P2P network of IPFS.  
So now, how the system looks for that specific hash among thousands of peers?  
Does it use flooding or DHT?  
If it uses DHT, then how the DHT locates the peer (or finds nearest peer) that holds the file while the file doesn’t follow any distribution mechanism?

---

<div class="post-metadata">

**Author:** ![leerspace](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@leerspace](https://discuss.ipfs.tech/u/leerspace)\
**Post date:** [September 28, 2018, 12:56pm UTC](https://discuss.ipfs.tech/t/how-ipfs-locates-a-specific-file/3946/2 "2018-09-28T12:56:46Z")

</div>

> [@LastExile16](#):
>
> In IPFS each peer randomly stores and shares any file that results in any hash. That means, the file is not distributed according to some mechanism, rather it’s random.

In general, node operators control which files their nodes store. It’s not random.

> [@LastExile16](#):
>
> So now, how the system looks for that specific hash among thousands of peers?  
> Does it use flooding or DHT?

It uses a DHT.

> [@LastExile16](#):
>
> If it uses DHT, then how the DHT locates the peer (or finds nearest peer) that holds the file while the file doesn’t follow any distribution mechanism?

It uses a node lookup, probably similar [to this](https://en.wikipedia.org/wiki/Kademlia#Locating_nodes). I’m not 100% sure on the implementation details for IPFS, though.
