<p>Obviously you would normally use a database with an efficient algorithm, but conceptually it goes like this:</p>

<p>1) You find the first instance of the account ID in the blockchain. If the account ID does not appear, <em>stop</em>. The account has no firstbits.</p>

<p>2) As a safety, make sure that there are at least six blocks after the block in which the account ID first appears. Otherwise, you risk having the firstbits change if that block is invalidated.</p>

<p>3) You search all previous transactions for the account ID that matches this account ID to as many characters as possible.</p>

<p>4) You output one more character from the account ID than the number of characters matched in step 3. This is the ID's firstbits.</p>

<p>So if the longest match prior to the first appearance of "13xdjsNsf5zJV9tpbxL6iirp1WdettzwyB" starts "13xdjq.." (and thus matches 5 characters), the firstbits for "13xdjsNsf5zJV9tpbxL6iirp1WdettzwyB" is "13xdjs" (the first 6 characters).</p>

<p>To go the other way, you search every account ID that appears in every transaction in the hash chain in appearance order. The first ID whose start matches all of the firstbits is the account ID for that firstbits.</p>

CC BY-SA 3.0
2014-02-20T10:04:08.510Z
Just to clarify: "account ID" in the above means "Address, converted to all lowercase". Theoretically, this means that an address might have no firstbits if it is identical to a previous address except for having a different case for some of its letters. In practice, the probability of this is minuscule.
Daniel H
CC BY-SA 3.0
2011-11-30T01:00:15.040Z
2011-12-01T19:51:12.110Z
2011-12-01T19:51:12.110Z
David Schwartz
<p>Is the algorithm used by FirstBits to create their shortened addresses described anywhere, so that anyone wanting to automatically generate them could generate the same result as asking the website for each individual address?</p>

<p>For example, when a block explorer like <a href="http://blockchain.info/" rel="nofollow">http://blockchain.info/</a> wants to include FirstBits for every address, how does it generate them fast without overloading the FB website?</p>

<address><algorithms><address-format>
FirstBits address shortening algorithm
ThePiachu
# FirstBits address shortening algorithm

(Asked by: username_0 on 2011-11-29)

Is the algorithm used by FirstBits to create their shortened addresses described anywhere, so that anyone wanting to automatically generate them could generate the same result as asking the website for each individual address?

For example, when a block explorer like <http://blockchain.info/> wants to include FirstBits for every address, how does it generate them fast without overloading the FB website?

**Tags:** address, algorithms, address-format


---

## 1 answers

### Answer by username_1 on 2011-11-30. Score: 3 | Accepted answer

Obviously you would normally use a database with an efficient algorithm, but conceptually it goes like this:

1) You find the first instance of the account ID in the blockchain. If the account ID does not appear, *stop*. The account has no firstbits.

2) As a safety, make sure that there are at least six blocks after the block in which the account ID first appears. Otherwise, you risk having the firstbits change if that block is invalidated.

3) You search all previous transactions for the account ID that matches this account ID to as many characters as possible.

4) You output one more character from the account ID than the number of characters matched in step 3. This is the ID's firstbits.

So if the longest match prior to the first appearance of "13xdjsNsf5zJV9tpbxL6iirp1WdettzwyB" starts "13xdjq.." (and thus matches 5 characters), the firstbits for "13xdjsNsf5zJV9tpbxL6iirp1WdettzwyB" is "13xdjs" (the first 6 characters).

To go the other way, you search every account ID that appears in every transaction in the hash chain in appearance order. The first ID whose start matches all of the firstbits is the account ID for that firstbits.

> **Comments:**
> **username_2**: Just to clarify: "account ID" in the above means "Address, converted to all lowercase". Theoretically, this means that an address might have no firstbits if it is identical to a previous address except for having a different case for some of its letters. In practice, the probability of this is minuscule.  

---

