<p>If there are an odd number of nodes on any level of the merkle tree, the last node is duplicated and hashed with itself.n</p>

<p>If there were a Tx4, the diagram would look like this</p>

<pre><code>                  Root (Hash01234444)
               /                      \
        Hash0123                 Hash4444
        /      \                    /     \
   Hash01      Hash23           Hash44     Hash44
   /   \        /   \             /   \
Hash0  Hash1  Hash2  Hash3     Hash4   Hash4
</code></pre>

CC BY-SA 4.0
2018-09-20T09:02:17.547Z
Thank you, but does not this approach cause "overlapping" for storing transactions in a block? (Regarding to the space limitation we logically need to saving space and decreasing the size of data, isn't it?)
Questioner
CC BY-SA 4.0
2018-09-20T13:59:54.097Z
Transactions are not stored like that. This duplication is only done at calculation time. There is no duplicated transaction stored in the block. It is simply part of the merkle root computation algorithm that the duplication is done.
Ava Chow
CC BY-SA 4.0
2018-09-20T14:40:18.640Z
@Thank you, It's OK. However, I mean "duplication of **hash**" and not duplication of transactions. However, since in a hash algorithm like `SHA256` the size of output is always fix, so ex. in your example, size of `Hash01234444` is equal to size of `Hash01234`, so we do not need any more space for `Hash01234444`. Hope I am right.
Questioner
CC BY-SA 4.0
2018-09-20T14:56:04.230Z
The hashes aren't stored.
Ava Chow
CC BY-SA 4.0
2018-09-20T15:05:11.657Z
Even "Root Hash" ?! but in the above figure it's shown that transactions hash is store in the the block (in block header). Is this figure wrong? or I did not understand it correctly ? Thanks
Questioner
CC BY-SA 4.0
2018-09-20T15:06:04.217Z
The merkle root (root hash in the diagram) is stored. That is the only hash stored. It is a fixed size, regardless of the rest of the merkle tree. The hashes in the merkle tree are not stored.
Ava Chow
CC BY-SA 4.0
2018-09-18T13:28:54.623Z
2018-09-18T13:28:54.623Z
Ava Chow
<p>According to definition and structure of the Merkle Tree, apparently, the number of transactions in a block that inserted in a Merkle Tree structure must be even (and not odd), is not it?</p>

<p>Please see the following figure which shows a Merkle Tree:</p>

<p><a href="https://i.sstatic.net/eetdg.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/eetdg.jpg" alt="enter image description here"></a></p>

<p>All the examples that I have seen, are like this one, meaning that apparently always number of transactions in a Merkle Tree are even (ex. in the example above there are <strong>four</strong> transactions). <strong>Is there an example in which number of transactions would be odd? And what happens if number of transaction are odd? (ex. how to insert 5 transactions in above example?)</strong> </p>

<merkle-tree>
Are number of transactions in Merkle Tree always "even"?
Questioner
# Are number of transactions in Merkle Tree always "even"?

(Asked by: username_0 on 2018-09-18)

According to definition and structure of the Merkle Tree, apparently, the number of transactions in a block that inserted in a Merkle Tree structure must be even (and not odd), is not it?

Please see the following figure which shows a Merkle Tree:

[![enter image description here](https://i.sstatic.net/eetdg.jpg)](https://i.sstatic.net/eetdg.jpg)

All the examples that I have seen, are like this one, meaning that apparently always number of transactions in a Merkle Tree are even (ex. in the example above there are **four** transactions). **Is there an example in which number of transactions would be odd? And what happens if number of transaction are odd? (ex. how to insert 5 transactions in above example?)**

**Tags:** merkle-tree


---

## 1 answers

### Answer by username_1 on 2018-09-18. Score: 13 | Accepted answer

If there are an odd number of nodes on any level of the merkle tree, the last node is duplicated and hashed with itself.n

If there were a Tx4, the diagram would look like this

```
                  Root (Hash01234444)
               /                      \
        Hash0123                 Hash4444
        /      \                    /     \
   Hash01      Hash23           Hash44     Hash44
   /   \        /   \             /   \
Hash0  Hash1  Hash2  Hash3     Hash4   Hash4

```

> **Comments:**
> **username_0**: Thank you, but does not this approach cause "overlapping" for storing transactions in a block? (Regarding to the space limitation we logically need to saving space and decreasing the size of data, isn't it?)  
> **username_1**: Transactions are not stored like that. This duplication is only done at calculation time. There is no duplicated transaction stored in the block. It is simply part of the merkle root computation algorithm that the duplication is done.  
> **username_0**: @Thank you, It's OK. However, I mean "duplication of **hash**" and not duplication of transactions. However, since in a hash algorithm like `SHA256` the size of output is always fix, so ex. in your example, size of `Hash01234444` is equal to size of `Hash01234`, so we do not need any more space for `Hash01234444`. Hope I am right.  
> **username_1**: The hashes aren't stored.  
> **username_0**: Even "Root Hash" ?! but in the above figure it's shown that transactions hash is store in the the block (in block header). Is this figure wrong? or I did not understand it correctly ? Thanks  
> **username_1**: The merkle root (root hash in the diagram) is stored. That is the only hash stored. It is a fixed size, regardless of the rest of the merkle tree. The hashes in the merkle tree are not stored.  

---

