Network and blocks
What is SHA-256?
SHA-256 is the hash function Bitcoin uses for proof of work, applied twice to each block header.
- Output
- 256 bits, 64 hex characters
- Works in
- 64 rounds on 512-bit blocks
- Published
- 2001, US standard FIPS 180
- In Bitcoin
- Applied twice
- Machines rated in
- TH/s and J/TH
What it means in practice
It turns any input into a 256-bit output that cannot be predicted without doing the calculation, which is what makes mining a fair search. Bitcoin, Bitcoin Cash and several other coins use the same algorithm, so the same machines can mine any of them. SHA-256 machines are rated in TH/s and J/TH.
What happens to the input
The input is padded and cut into blocks of 512 bits. Eight working numbers of 32 bits start from fixed values, and 64 rounds of adding, rotating and combining mix each block into them. After the last block, the eight numbers side by side are the 256-bit result.
The starting values and the round constants come from the square and cube roots of small prime numbers, so anyone can see they were not chosen to hide something.
All of it is simple arithmetic on 32-bit numbers, which is why it fits so well into silicon.
Three properties that mining uses
The same input always gives the same output, so anyone can check a block in a millionth of a second. Changing one bit changes about half of the output bits, so there is no getting warmer. And nobody knows a way to work backward from a wanted output, so trying is the only method.
Example figures: at a difficulty of 140T a block takes 6.01 × 10^23 attempts on average, close to 2^79. Written in hexadecimal, a winning hash therefore starts with about 19 or 20 zeros.
Hashing is not encryption
Encryption can be undone with a key. A hash cannot be undone at all, and it has no key. A 1 MB file and a short word both give 64 characters, and neither can be recovered from them.
A mining chip is also no threat to passwords or wallets. It is built to hash 80-byte headers with a changing nonce and cannot be fed anything else.
Use it yourself: checking a download
Firmware authors publish a SHA-256 checksum next to a file. Calculate your own copy’s value and compare all 64 characters. A match means the file arrived exactly as published.
On Windows: certutil -hashfile firmware.bin SHA256. On macOS: shasum -a 256 firmware.bin. On Linux: sha256sum firmware.bin. Take the published value from the author’s own site.
Which coins a SHA-256 machine can mine
Bitcoin and Bitcoin Cash are the ones most pools offer. Smaller SHA-256 chains exist, some of them merge-mined with Bitcoin. The machine does not care: the same chips, the same watts and a different pool address.
Other coins use the function inside their software without using it for mining. What matters for a machine is the proof-of-work algorithm.
A machine can change between SHA-256 coins as often as you like. Income per terahash stays close between the larger ones, because other miners do the same.
Worked example
Because every Bitcoin hash is a double SHA-256, a 200 TH/s machine performs about 4 × 10^14 single SHA-256 operations per second.
Example figures, not live data.
Common mistakes
- Comparing only the first and last few characters of a checksum for a file that matters.
- Expecting a SHA-256 machine to mine Litecoin or Kaspa.
- Calling a hash an encryption of its input.
Common questions
Why does Bitcoin apply SHA-256 twice?
The paper gives no reason. The usual explanation is protection against a property of single hashing that lets data be appended to an input. The double form is used for headers and transactions alike.
Can two inputs have the same SHA-256?
In theory yes. No pair has ever been found, and the space is vast.
What is SHA-256d?
The d stands for double. It is the name some pools and tools use for Bitcoin’s algorithm.