What is a Hash?

A hash is a fixed-length digital fingerprint produced by running data through a hash function. Blockchains use hashes to link blocks together, identify transactions and power proof-of-work mining.

On this page 6
  1. How does a hash function work?
  2. Why are hashes used in blockchains?
  3. Hashing in mining and what hashrate means
  4. Hashing vs. encryption
  5. Frequently asked questions
  6. Source

A hash is a fixed-length digital fingerprint created by running data through a hash function. Whether the input is a single word or a multi-gigabyte file, the output is always a string of the same length. In crypto, hashing is the building block that chains blocks together, identifies transactions and makes mining possible.

How does a hash function work?

A hash function scrambles input data through a series of mathematical steps and outputs a compact digest. SHA-256, the function Bitcoin uses, always returns 256 bits, which is 64 characters in hexadecimal. The hash of the word “bitcoin” and the hash of an entire book are exactly the same length.

A cryptographically secure hash function has four key properties:

  • Deterministic: the same input always produces the same output.
  • Avalanche effect: changing a single character in the input produces a completely different output.
  • Pre-image resistance: you cannot work backwards from the output to recover the input in practice.
  • Collision resistance: it is extremely hard to deliberately find two different inputs with the same hash.

Why are hashes used in blockchains?

Every block stores the hash of the block before it. If someone altered a single record in an old block, that block’s hash would change and every link after it would break. This is what makes a blockchain tamper-evident: rewriting history means redoing every block that follows.

Transactions inside a block are also hashed in pairs to form a Merkle tree, which ends in a single value called the Merkle root. That root sits in the block header, so anyone can prove a transaction is included in a block without downloading the whole block. The transaction ID (TXID) you paste into a block explorer is itself a hash of the transaction data.

Addresses rely on hashing too. Many Bitcoin address types are derived by hashing a public key with SHA-256 and then RIPEMD-160, while Ethereum uses a different function called Keccak-256.

Hashing in mining and what hashrate means

On proof-of-work networks, miners repeatedly tweak a candidate block header and hash it again, looking for a result below a target set by the network. There is no shortcut, so it takes an enormous number of attempts. Checking a winning answer, by contrast, takes a single hash.

The total number of guesses all miners make per second is called the hashrate. Bitcoin’s hashrate is now measured in exahashes per second, or quintillions of guesses. A higher hashrate raises the cost for anyone trying to rewrite the chain, which is why it is often used as a rough gauge of network security. Our guide to Bitcoin mining covers the economics in more detail.

Hashing vs. encryption

Encryption locks data with a key so it can be unlocked again with the right key. Hashing is one-way by design: its purpose is to summarize and verify data, not to hide it. Short or predictable inputs, such as a weak password, can still be found by guessing candidates and comparing hashes, which is why password storage adds extra protections such as salting and deliberately slow algorithms.

You can also use hashes yourself. Many wallet developers publish a SHA-256 checksum next to each download; if the hash of the file you downloaded matches the published one, you know the file was not altered along the way.

Frequently asked questions

Can a hash be reversed?

Not with a secure hash function. There is no known practical way to compute the input from the output, although short or guessable inputs can be found by brute force.

Can two different inputs have the same hash?

In theory yes, because the output length is fixed. For functions considered secure, such as SHA-256, nobody has found a practical way to produce such a collision on purpose.

What happens if Bitcoin’s hashrate drops?

Blocks temporarily arrive more slowly. At the next difficulty adjustment, the network lowers the difficulty so that blocks return to an average of roughly ten minutes.

Source

Read next