Fallos frecuentes que deberias evitar en la remodelacion del hogar

Remodelar su casa es una gran inversión financiera y emocional. Para proyectos de remodelación más grandes, seguramente será una de las compras más grandes que haya hecho. Debido a que es tan poco…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




How many characters Bitcoin addresses can be?

I don’t have any bitcoins, so I don’t lose anything if the following is incorrect. However let me know if you find any mistake.

You can find different pieces of information on the internet about the possible length of Bitcoin addresses, but not all of them are true.

Google snippet featuring false information

Bitcoin addresses look different on the blockchain and when they are presented to users. Users don’t like binary encoding and they also want to avoid misreading and mistyping the addresses. The Bitcoin addresses we see are thus encoded for user convenience. There were two such encodings invented so far: Base58Check and Bech32.

The algorithm first builds a sequence of bytes the following way:

1 byte: version
20 byte: payload (the public key hash or the script hash)
4 byte: checksum

So here we are: we now encoded our fixed length sequence of bytes into a variable length sequence of characters, where the length depends on the values of the original bytes. But what are the limits of the length of a valid Bitcoin address?

When we convert a number to a numeral system with a smaller set of digits, we can expect that the resulting number will be longer. (One digit can encode less, so we need more of them.) But when we copy the leading zero digits, then we use the same number of digits in the output as in the input.

The full zero version and payload fields (together with the proper checksum) give the 1111111111111111111114oLvT2 valid Bitcoin address, which consists of 27 characters. But it’s not the shortest possible valid Bitcoin address, because if we increment the payload, then the 5 non-zero bytes easily fit in the 6 base58 digits, and as we have one less 1-character (zero digit) in the output, our new Bitcoin address will be only 26 characters: 11111111111111111111BZbvjr. This illustrates an ugly property of the Base58Check encoding: the output length does not monotonically increase with the input value.

For analysis, it’s best to separate the Bitcoin address to 2 parts: the leading zero digits and the significant digits. The length of the second part now does monotonically increase with the input value, and we can easily calculate a length range based on the input range.

For completeness let’s now see the Bech32 addresses!

There are 2 kinds of Bech32 addresses in use currently, and luckily both of them have fixed length. They are segwit addresses with the following general format:

2 character: human-readable part (“bc” for mainnet, “tb” for testnet)
1 character: separator (“1”)
1 character: witness version (“q”, meaning version 0)
n character: witness program encoded to base32
6 character: checksum

P2WPKH Bech32 addresses (having a 20 byte witness program) are 42 (20*8/5+10) character long. An example from BIP173 is bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4.

P2WSH Bech32 addresses (having a 32 byte witness program) are 62 (32*8/5+10 rounded up) character long. An example from BIP173 is bc1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3qccfmv3.

That’s it, Bech32 was easy.

Add a comment

Related posts:

Coping with the Unknown

Having been through a violent stroke about 10 years ago, and defying recovery odds and prognoses, I feel that I can offer a wee bit of insight and advice regarding caring for one’s self and staying…