network

hash

A mathematical function that converts any input into a fixed-length string of characters. Bitcoin uses SHA-256 to link blocks and verify data. Hashes are one-way: the original input cannot be recovered from the output.

A hash function is a mathematical algorithm that takes any input, whether a single word, a transaction record, or an entire block of data, and produces a fixed-length string of characters called a hash or digest. No matter how large or small the input, the output is always the same length. Bitcoin uses SHA-256, which produces a 256-bit output, typically displayed as a 64-character hexadecimal string.

Hash functions are one-way: given a hash output, it is computationally infeasible to determine the original input. They are also deterministic, meaning the same input always produces the same output. Even a tiny change to the input, altering a single character, produces a completely different hash. This sensitivity is known as the avalanche effect and makes hashes reliable tools for detecting any modification to data.

In Bitcoin, hashes serve several critical roles. Each block contains the hash of the previous block, which chains them together and makes the blockchain tamper-resistant. Mining requires finding a hash output that falls below a specific target value, which demands enormous computational effort. Transaction identifiers are also hashes, allowing anyone to look up any transaction in the blockchain by its unique fingerprint.

Frequently asked questions

What is SHA-256 and why does Bitcoin use it?

SHA-256 is a member of the SHA-2 family of cryptographic hash functions developed by the United States National Security Agency. It produces a 256-bit output for any input. Bitcoin uses it because it is fast to compute, produces outputs that appear random, and is resistant to collision attacks, meaning it is practically impossible to find two different inputs that produce the same hash. It is used in both the proof-of-work mining algorithm and in address generation.

Why can't you reverse a hash to recover the original data?

Hash functions are designed to be one-way by construction. The mathematical operations involved, such as bitwise operations, modular arithmetic, and mixing steps, discard information at each stage. There is no mathematical inverse operation. The only practical way to find an input that produces a given hash is to try inputs until one matches, which requires astronomical computational effort for a 256-bit hash.

How do hashes secure the Bitcoin blockchain?

Each block in the blockchain includes the hash of the previous block in its header. This creates a dependency chain: changing any historical block would change its hash, which would break the link to the next block, which in turn would require recalculating that block, and every block after it. Since each block requires substantial proof-of-work to produce, rewriting history becomes exponentially harder the further back the change reaches.