# Why do IPFS hashes start with "Qm"?

**URL:** <https://discuss.ipfs.tech/t/why-do-ipfs-hashes-start-with-qm/477>\
**Category:** Help\
**Created:** [May 23, 2017, 12:21am UTC](https://discuss.ipfs.tech/t/why-do-ipfs-hashes-start-with-qm/477 "2017-05-23T00:21:28Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:21am UTC](https://discuss.ipfs.tech/t/why-do-ipfs-hashes-start-with-qm/477/1 "2017-05-23T00:21:29Z")

</div>

_From @moreati on Sun Jul 26 2015 14:20:24 GMT+0000 (UTC)_  
  
Answer:

IPFS represents the hash of files and objects using [Multihash](https://github.com/jbenet/multihash) format and [Base58](https://en.wikipedia.org/wiki/Base58) encoding. The letters `Qm` happen to correspond with the algorithm (SHA-256) and length (32 bytes) used by IPFS.

TODO:

- Is the prefix always ‘Qm’? Yes, in current builds  
  
  
_Copied from original issue: [Why do IPFS hashes start with "Qm"? · Issue #22 · ipfs-inactive/faq · GitHub](https://github.com/ipfs/faq/issues/22)_

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:21am UTC](https://discuss.ipfs.tech/t/why-do-ipfs-hashes-start-with-qm/477/2 "2017-05-23T00:21:42Z")

</div>

_From @jbenet on Mon Jul 27 2015 06:43:12 GMT+0000 (UTC)_  
  
\> Is the prefix always ‘Qm’?

No, if objects were hashed with other functions, the prefix would be different. try out this binary: [https://github.com/jbenet/go-multihash/tree/master/multihash](https://github.com/jbenet/go-multihash/tree/master/multihash)

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:21am UTC](https://discuss.ipfs.tech/t/why-do-ipfs-hashes-start-with-qm/477/3 "2017-05-23T00:21:48Z")

</div>

_From @moreati on Mon Jul 27 2015 08:35:00 GMT+0000 (UTC)_  
  
Thanks, when does IPFS use another function? So far I’ve only seen `Qm`.

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:21am UTC](https://discuss.ipfs.tech/t/why-do-ipfs-hashes-start-with-qm/477/4 "2017-05-23T00:21:54Z")

</div>

_From @jbenet on Mon Jul 27 2015 08:49:26 GMT+0000 (UTC)_  
  
@moreati we use sha256-256, but it’s not hard for someone to re-compile ipfs to use another function as a default, or change the importer code to add a way to specify the multihash choice.

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:21am UTC](https://discuss.ipfs.tech/t/why-do-ipfs-hashes-start-with-qm/477/5 "2017-05-23T00:21:58Z")

</div>

_From @RichardLitt on Mon May 02 2016 19:12:23 GMT+0000 (UTC)_  
  
I see this question a lot; reopening it and labelling it as ‘answered’ to increase visibility.

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:22am UTC](https://discuss.ipfs.tech/t/why-do-ipfs-hashes-start-with-qm/477/6 "2017-05-23T00:22:02Z")

</div>

_From @RichardLitt on Thu Oct 06 2016 19:14:52 GMT+0000 (UTC)_  
  
How is `Qm` the string? I’m a bit confused on that, because I don’t see it in any of the tables on the Multihash repo.

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:22am UTC](https://discuss.ipfs.tech/t/why-do-ipfs-hashes-start-with-qm/477/7 "2017-05-23T00:22:05Z")

</div>

_From @Kubuxu on Thu Oct 06 2016 20:50:21 GMT+0000 (UTC)_  
  
It is base58-btc encode of the two bytes prefix of that multihash.

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:22am UTC](https://discuss.ipfs.tech/t/why-do-ipfs-hashes-start-with-qm/477/8 "2017-05-23T00:22:07Z")

</div>

_From @JustinDrake on Tue Nov 22 2016 15:42:03 GMT+0000 (UTC)_  
  
I’m a bit confused by “The letters Qm happen to correspond with the algorithm (SHA-256) and length (32 bytes)”

Is it that `Q` corresponds to SHA-256, and `m` corresponds to `32`?

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:22am UTC](https://discuss.ipfs.tech/t/why-do-ipfs-hashes-start-with-qm/477/9 "2017-05-23T00:22:10Z")

</div>

_From @hsanjuan on Tue Nov 22 2016 16:06:55 GMT+0000 (UTC)_  
  
@JustinDrake If I got it right, multihashes start with a byte (0x12) which indicates the hashing algorithm, followed by another byte for length (0x20) . “Qm” letters are the result of those bytes encoded in base58.

Source: [https://github.com/multiformats/go-multihash/blob/master/multihash.go#L146](https://github.com/multiformats/go-multihash/blob/master/multihash.go#L146)

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:22am UTC](https://discuss.ipfs.tech/t/why-do-ipfs-hashes-start-with-qm/477/10 "2017-05-23T00:22:12Z")

</div>

_From @alexanderattar on Tue Apr 18 2017 19:55:42 GMT+0000 (UTC)_  
  
maybe I just haven’t put all the pieces together, but I’m wondering if anyone here can off-hand explain the steps for how one might precompute the IPFS hash (Under the current build) given some JSON. Thanks in advance!

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:22am UTC](https://discuss.ipfs.tech/t/why-do-ipfs-hashes-start-with-qm/477/11 "2017-05-23T00:22:13Z")

</div>

_From @RichardLitt on Tue Apr 18 2017 19:57:02 GMT+0000 (UTC)_  
  
@alexanderattar You can do that using `ipfs add -n`, iirc. It doesn’t add it to IPFS, it merely spits out the hash for you.

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:22am UTC](https://discuss.ipfs.tech/t/why-do-ipfs-hashes-start-with-qm/477/12 "2017-05-23T00:22:15Z")

</div>

_From @alexanderattar on Tue Apr 18 2017 20:09:49 GMT+0000 (UTC)_  
  
ah thanks @RichardLitt! I guess my question is actually in regard to how I would approach this programmatically by running the JSON through the encoding algorithms without necessarily using the IPFS CLI. I am looking to take some JSON I have in JavaScript and precompute the hash before sending to IPFS if that helps explain the use-case.

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:22am UTC](https://discuss.ipfs.tech/t/why-do-ipfs-hashes-start-with-qm/477/13 "2017-05-23T00:22:16Z")

</div>

_From @alexanderattar on Tue Apr 18 2017 21:12:32 GMT+0000 (UTC)_  
  
I just want to add that I have tried encrypting JSON via sha256 to get a hash such as 4f72333148622e4ae56e9c65d57aee47186cd6910ca080757ab72cc0c650f6bb and have prefixed this with 1220 and then taken the entire string with the prefix:

122000c75938d356b000b34e7f7885f8982f29d89af76c234a8d439486b40fdc5469

and after running that through a base58 encoding, I get a hash that resembles an IPFS hash with the prefixed Qm, but the hash is not consistent with was is returned from adding the same JSON to IPFS via the command-line. I am wondering if I am doing something wrong, or missing a step. Thanks again!

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:22am UTC](https://discuss.ipfs.tech/t/why-do-ipfs-hashes-start-with-qm/477/14 "2017-05-23T00:22:17Z")

</div>

_From @Kubuxu on Tue Apr 18 2017 21:45:08 GMT+0000 (UTC)_  
  
Try doing the add with `--raw-leaves` option instead but now you have to add a CID at the front. [https://github.com/ipld/cid](https://github.com/ipld/cid)

Where raw block has multicodec of 0x55.

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:22am UTC](https://discuss.ipfs.tech/t/why-do-ipfs-hashes-start-with-qm/477/15 "2017-05-23T00:22:18Z")

</div>

_From @alexanderattar on Tue Apr 18 2017 22:01:44 GMT+0000 (UTC)_  
  
Thanks @Kubuxu but I just want to reiterate that I am not looking to use the ipfs CLI, but rather go through the necessary encryption and encoding steps to get from JSON to a IPFS hash. So far my method has been:

Take the JSON and encode via SHA256 to get the digest, then prefix the digest with 1220 as described [here](http://multiformats.io/multihash/#sha2-256-256-bits-aka-sha256), so the entire hex string is composed of the prefix plus the digest and then base58 encoded. Does any of this approach sound incorrect?

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:22am UTC](https://discuss.ipfs.tech/t/why-do-ipfs-hashes-start-with-qm/477/16 "2017-05-23T00:22:19Z")

</div>

_From @Kubuxu on Tue Apr 18 2017 22:03:24 GMT+0000 (UTC)_  
  
IPFS by default also wraps the file you give it into some metadata used by ipfs itself. That is why it is different. `--raw-leaves` utilizes CID to communicate to others that data under the hash has no wrapping.

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:22am UTC](https://discuss.ipfs.tech/t/why-do-ipfs-hashes-start-with-qm/477/17 "2017-05-23T00:22:20Z")

</div>

_From @alexanderattar on Wed Apr 19 2017 17:47:50 GMT+0000 (UTC)_  
  
Wow, I was not aware of that, but that does explain why the hash is different. Is there documentation on the metadata IPFS wraps the file in before generating the SHA256 digest? I tried using the --raw-leaves flag which indeed gives me a different hash:

`{"Name":"myfile.txt","Hash":"zb2rhnyuQdBJVhb3j7FAL1NRUrQu4TMkb7zED9S5sh2YCKd62"}`

but I have not found any documentation on what algorithms and processing the data goes through to produce this hash.
