<p>The way Bitcoin checks a public address is using what is called <strong>Base58Check</strong>. While the <a href="https://en.bitcoin.it/wiki/Base58Check_encoding#Creating_a_Base58Check_string" rel="noreferrer">Bitcoin Wiki covers Base58Check</a>, I'll outline how it works in both abstract and technical terms.</p>

<p><img src="https://i.sstatic.net/lhWd6.png" alt="Diagram of Base58Check"></p>

<p>The whole idea of Base58Check is to prevent invalid addresses. This is done by adding digits to the start (00) and end of the Base58 value (4 bytes of double SHA256 hash). </p>

<ol>
<li>Add <code>00</code> to the start of Base58 value ie <code>00</code> + <code>BASE58</code> ==> <code>00BASE58</code></li>
<li>Checksum = 1st 8 digits from <code>SHA256(SHA256(00BASE58))</code></li>
</ol>

<p><code>BASE58Check = (00)(BASE58_SHA256RIPEMD160_HEXADECIMAL_VALUE)(CHECKSUM)</code> (parenthesis for visualisation only, all other data is correct in size, ie CHECKSUM = 8 chars)</p>

<p>The best way to visualize all this is with <a href="https://gobittest.appspot.com/Address" rel="noreferrer">The Piachu's App</a></p>

CC BY-SA 3.0
2014-11-07T03:05:55.503Z
Excellent answer and infographic!
Nick ODell
CC BY-SA 3.0
2014-11-07T02:31:01.640Z
2014-11-07T02:31:01.640Z
Wizard Of Ozzie
<p><a href="http://rosettacode.org/wiki/Bitcoin/address_validation" rel="nofollow noreferrer">Rosetta Code</a> has several example implementations in multiple languages.</p>
<h3>Python 2 &amp; 3</h3>
<pre><code>import codecs
from hashlib import sha256

digits58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'

def to_bytes(n, length):
    s = '%x' % n
    s = s.rjust(length*2, '0')
    s = codecs.decode(s.encode(&quot;UTF-8&quot;), 'hex_codec')
    return s

def decode_base58(bc, length):
    n = 0
    for char in bc:
        n = n * 58 + digits58.index(char)
    return to_bytes(n, length)

def check_bc(bc):
    bcbytes = decode_base58(bc, 25)

    if bcbytes[0] not in [0x00, 0x05]:
        return False

    return bcbytes[-4:] == sha256(sha256(bcbytes[:-4]).digest()).digest()[:4]
    
if __name__ == '__main__':
    print(check_bc('1111111111111111111114oLvT2'))
</code></pre>

CC BY-SA 3.0
2017-08-19T00:29:58.437Z
This cannot be used to validate bitcoin addresses. Returns `True` for the following strings:`DPPGKttReEyzL5iQJExKvmS68QWTFvaecJ`, `MfwMaegJ8qB4QMvtFqgfaD8o2FrYse7LU`, `mtcrV4Wux9xPapqHz13eAEmynVhyfNTY7u`
Max Malysh
CC BY-SA 3.0
2017-08-19T00:31:51.390Z
If you wish to check the version byte, check that too.
Nick ODell
CC BY-SA 3.0
2014-11-07T03:03:33.703Z
2017-09-15T18:02:32.230Z
2020-06-16T11:10:03.350Z
Nick ODell
<p>I'm working on a Bitcoin ATM. We want to detect addresses that are entered incorrectly.</p>

<p>There's a checksum on Bitcoin addresses - but how can we check it?</p>

CC BY-SA 3.0
2014-11-06T03:32:33.280Z
ah.found it          if(!validateAddress(rcp.address))
        {
            return InvalidAddress;
        }
Willipm
CC BY-SA 3.0
2014-11-06T08:51:33.897Z
If you can choose the option of answering your own question for future queries that'd help!
Wizard Of Ozzie
CC BY-SA 3.0
2014-11-07T01:07:46.487Z
@WizardOfOzzie: Right on. Also, if you know that the information is correct, feel free to use any "comment answer" as a starting point to create a full answer. It might be nice to quote the original commenter, but anyone has my blessing to the reputation for the answer if he does that.
Murch
<address-format><checksum>
How do I check the checksum of a Bitcoin address?
Willipm
# How do I check the checksum of a Bitcoin address?

(Asked by: username_0 on 2014-11-06)

I'm working on a Bitcoin ATM. We want to detect addresses that are entered incorrectly.

There's a checksum on Bitcoin addresses - but how can we check it?

**Tags:** address-format, checksum

> **Comments:**
> **username_0**: ah.found it          if(!validateAddress(rcp.address))         {             return InvalidAddress;         }  
> **username_1**: If you can choose the option of answering your own question for future queries that'd help!  
> **username_2**: @username_1: Right on. Also, if you know that the information is correct, feel free to use any "comment answer" as a starting point to create a full answer. It might be nice to quote the original commenter, but anyone has my blessing to the reputation for the answer if he does that.  

---

## 2 answers

### Answer by username_1 on 2014-11-07. Score: 15

The way Bitcoin checks a public address is using what is called **Base58Check**. While the [Bitcoin Wiki covers Base58Check](https://en.bitcoin.it/wiki/Base58Check_encoding#Creating_a_Base58Check_string), I'll outline how it works in both abstract and technical terms.

![Diagram of Base58Check](https://i.sstatic.net/lhWd6.png)

The whole idea of Base58Check is to prevent invalid addresses. This is done by adding digits to the start (00) and end of the Base58 value (4 bytes of double SHA256 hash).

1. Add `00` to the start of Base58 value ie `00` + `BASE58` ==> `00BASE58`
2. Checksum = 1st 8 digits from `SHA256(SHA256(00BASE58))`

`BASE58Check = (00)(BASE58_SHA256RIPEMD160_HEXADECIMAL_VALUE)(CHECKSUM)` (parenthesis for visualisation only, all other data is correct in size, ie CHECKSUM = 8 chars)

The best way to visualize all this is with [The Piachu's App](https://gobittest.appspot.com/Address)

> **Comments:**
> **username_3**: Excellent answer and infographic!  

---

### Answer by username_3 on 2014-11-07. Score: 6

[Rosetta Code](http://rosettacode.org/wiki/Bitcoin/address_validation) has several example implementations in multiple languages.

### Python 2 & 3

```
import codecs
from hashlib import sha256

digits58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'

def to_bytes(n, length):
    s = '%x' % n
    s = s.rjust(length*2, '0')
    s = codecs.decode(s.encode("UTF-8"), 'hex_codec')
    return s

def decode_base58(bc, length):
    n = 0
    for char in bc:
        n = n * 58 + digits58.index(char)
    return to_bytes(n, length)

def check_bc(bc):
    bcbytes = decode_base58(bc, 25)

    if bcbytes[0] not in [0x00, 0x05]:
        return False

    return bcbytes[-4:] == sha256(sha256(bcbytes[:-4]).digest()).digest()[:4]
    
if __name__ == '__main__':
    print(check_bc('1111111111111111111114oLvT2'))

```

> **Comments:**
> **username_4**: This cannot be used to validate bitcoin addresses. Returns `True` for the following strings:`DPPGKttReEyzL5iQJExKvmS68QWTFvaecJ`, `MfwMaegJ8qB4QMvtFqgfaD8o2FrYse7LU`, `mtcrV4Wux9xPapqHz13eAEmynVhyfNTY7u`  
> **username_3**: If you wish to check the version byte, check that too.  

---

