<p>There is a so-called <strong>gap limit</strong>. In Electrum, it's 20 by default but can be changed. But if you changed it up, remember that! Preferably write it next to your wallet's seed.</p>

<p>This means that the HD wallet determines the first 20 addresses and checks on a server whether any of them have every been involved in a transaction. Let's say these addresses are numbered. Number 7 is the one with the highest number to ever have been involved in a transaction. Then, 7+20 = 27 is computed and all addresses up until and including 27 are checked. It's found that 21, 23, and 25 have been involved in transactions. Then, 25+20 = 45 is computed and all addresses up until and including 45 are checked. It's found that none of the addresses from 28 to 45 ever had activity on them. Therefore, the search is stopped because there is a cap of at least 20 addresses. If address 46 had a transaction on it, that's not discovered until the user uses the wallet enough such that that address is searched for activity or the gap limit is increased.</p>

CC BY-SA 3.0
2017-01-09T14:56:12.073Z
Since the asker tagged his question with "multibit-hd", it may be worth noting that Multibit also follows [BIP44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#Address_gap_limit) and uses the same gap limit of 20.
Murch
CC BY-SA 3.0
2017-01-09T15:01:03.270Z
@Murch It seemed to me that OP wanted to know how it works in general and just stated an example HD wallet. Anyways, regarding Multibit HD: In their [gap limit explanation](https://multibit.org/help/hd0.1/gap-limit.html), they refer to BIP 44 and then link to [this paragraph](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#Address_gap_limit) which states: "Address gap limit is currently set to 20. If the software hits 20 unused addresses in a row, it expects there are no used addresses beyond this point and stops searching the address chain. [...]"
UTF-8
CC BY-SA 3.0
2017-01-09T15:02:26.773Z
Yes, that's the same page that I've linked to. The information should be added to the answer though, because probably the asker was interested in Multibit, or they wouldn't have added the tag after adding the more generic [deterministic] and [hd-wallet]. ;)
Murch
CC BY-SA 3.0
2017-01-03T21:55:28.157Z
2017-01-03T21:55:28.157Z
UTF-8
<p>When I have a seed and use it to recover my keys, how does a client find out which keys I had and their respective amounts?</p>

<p>To clarify, I understand how a <a href="https://bitcoin.stackexchange.com/q/45978/44541">deterministic key</a> works and that we can generate more keys from it. What I'm not sure is how the client knows how many private keys / wallets I had and the units of currency in each of them.</p>

<bip32-hd-wallets><seed><deterministic-wallets><multibit-hd>
How does the client know the number of keys and coins when recovering from a seed?
Daniel
# How does the client know the number of keys and coins when recovering from a seed?

(Asked by: username_0 on 2017-01-03)

When I have a seed and use it to recover my keys, how does a client find out which keys I had and their respective amounts?

To clarify, I understand how a [deterministic key](https://bitcoin.stackexchange.com/q/45978/44541) works and that we can generate more keys from it. What I'm not sure is how the client knows how many private keys / wallets I had and the units of currency in each of them.

**Tags:** bip32-hd-wallets, seed, deterministic-wallets, multibit-hd


---

## 1 answers

### Answer by username_1 on 2017-01-03. Score: 8 | Accepted answer

There is a so-called **gap limit**. In Electrum, it's 20 by default but can be changed. But if you changed it up, remember that! Preferably write it next to your wallet's seed.

This means that the HD wallet determines the first 20 addresses and checks on a server whether any of them have every been involved in a transaction. Let's say these addresses are numbered. Number 7 is the one with the highest number to ever have been involved in a transaction. Then, 7+20 = 27 is computed and all addresses up until and including 27 are checked. It's found that 21, 23, and 25 have been involved in transactions. Then, 25+20 = 45 is computed and all addresses up until and including 45 are checked. It's found that none of the addresses from 28 to 45 ever had activity on them. Therefore, the search is stopped because there is a cap of at least 20 addresses. If address 46 had a transaction on it, that's not discovered until the user uses the wallet enough such that that address is searched for activity or the gap limit is increased.

> **Comments:**
> **username_2**: Since the asker tagged his question with "multibit-hd", it may be worth noting that Multibit also follows [BIP44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#Address_gap_limit) and uses the same gap limit of 20.  
> **username_1**: @username_2 It seemed to me that OP wanted to know how it works in general and just stated an example HD wallet. Anyways, regarding Multibit HD: In their [gap limit explanation](https://multibit.org/help/hd0.1/gap-limit.html), they refer to BIP 44 and then link to [this paragraph](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#Address_gap_limit) which states: "Address gap limit is currently set to 20. If the software hits 20 unused addresses in a row, it expects there are no used addresses beyond this point and stops searching the address chain. [...]"  
> **username_2**: Yes, that's the same page that I've linked to. The information should be added to the answer though, because probably the asker was interested in Multibit, or they wouldn't have added the tag after adding the more generic [deterministic] and [hd-wallet]. ;)  

---

