A hash helps secure a blockchain by giving every piece of data a unique, fixed-length fingerprint that changes completely if even one character of the data changes. Each block stores the hash of the block before it, so editing an old transaction changes that block’s hash, breaks the link to every later block and is spotted immediately by every node that checks the chain.
Hashing on its own only makes tampering visible. What makes tampering expensive is the consensus mechanism built on top of it, such as Bitcoin’s proof of work. This guide explains both, with the exact hash functions Bitcoin and Ethereum use, how Merkle trees and addresses work, and where hashing stops protecting you.
What a cryptographic hash function is
A cryptographic hash function takes an input of any size, from one word to a whole file, and returns a short output of fixed length called a hash or digest. SHA-256, the function at the heart of Bitcoin, always returns 256 bits, usually written as 64 hexadecimal characters. It is one of the Secure Hash Algorithms specified by the US National Institute of Standards and Technology in FIPS 180-4.
Here is what that looks like in practice. Two messages that differ by a single digit produce completely unrelated SHA-256 hashes:
Pay Alice 10 BTC→d6692c17dd8b0a548fff082417f1784f5c9918094912d484f4bc101584ce5561Pay Alice 11 BTC→c6540c3293657f6f6079ed9240ccf29f155112942474ab1a869f9ba73a6d796e
The properties that matter for security
- Deterministic: the same input always gives the same hash, so any node can recompute it and check it.
- Fast to compute: checking a hash is cheap, which lets thousands of nodes verify every block.
- Preimage resistance: given a hash, it is computationally infeasible to find an input that produces it. You cannot work backwards from the fingerprint to the data.
- Second-preimage resistance: given one input, it is infeasible to find a different input with the same hash. An attacker cannot swap in a forged transaction that matches the original’s hash.
- Collision resistance: it is infeasible to find any two different inputs with the same hash. Collisions must exist in theory, because there are more possible inputs than outputs, but no one should be able to find one.
- Avalanche effect: a tiny change to the input changes roughly half of the output bits, as the example above shows, so small edits cannot hide.
Hashing is not encryption. Encryption is designed to be reversed by someone with the key; a hash is designed never to be reversed. Blockchains use hashes for integrity and identity, and digital signatures (not encryption) to prove who authorised a transaction.
How hashes chain blocks together
In Bitcoin, every block starts with an 80-byte header. According to the Bitcoin developer reference, the header contains six fields: a version number, the hash of the previous block’s header, the Merkle root of the block’s transactions, a timestamp, the encoded difficulty target (nBits) and a nonce. The header is hashed with SHA-256 twice, written SHA256(SHA256()), to produce the block’s own hash.
Because each header includes the previous block’s hash, the blocks form a chain in which every link depends on everything before it. Change one transaction in block 100 and the following happens:
- The transaction’s ID (itself a double SHA-256 hash) changes.
- The Merkle root in block 100’s header changes, so block 100’s hash changes.
- Block 101 still points to the old hash of block 100, so the link is broken and every honest node rejects the edited chain.
To make the edit stick, an attacker would have to rebuild block 100 and every block after it, and then convince the network to accept that version. That is where proof of work comes in.
Merkle trees: one hash for thousands of transactions
A block can hold thousands of transactions, but its header has room for only one 32-byte summary of them. That summary is the Merkle root. Transaction IDs are hashed in pairs, the results are hashed in pairs again, and so on until one hash remains. If a level has an odd number of hashes, Bitcoin pairs the last one with a copy of itself.
Merkle trees give blockchains two useful abilities, both described in the Bitcoin whitepaper:
- Tamper evidence for every transaction: changing any transaction changes the root, and therefore the block hash.
- Light verification: a wallet can prove a transaction is in a block using only the block header and a short “Merkle branch” of sibling hashes, without downloading the whole block. The whitepaper calls this simplified payment verification.
Ethereum uses a related structure, the Merkle Patricia trie, hashed with Keccak-256. Each block header carries three roots, for the state, the transactions and the receipts, as explained in ethereum.org’s documentation. At the time of writing, ethereum.org also notes a planned move to Verkle trees.
Free resource
Blockchain project scoping checklist
Want this applied to your project? Our engineers will send it with notes for your stack.
Proof of work: making the chain expensive to rewrite
In Bitcoin, a block is valid only if its header hash is at or below a target value set by the network. Because hash outputs are unpredictable, the only way to find a valid hash is to try again and again, changing the nonce (and other fields) each time. This search is mining.
The Bitcoin developer guide explains that every 2,016 blocks the network compares how long those blocks took with the ideal two weeks and adjusts the difficulty, which keeps blocks at roughly ten minutes apart on average.
This is what turns hashing into real security. Anyone can check a block’s proof of work with one hash calculation, but producing it takes enormous computing effort. To rewrite history, an attacker has to redo the work for the edited block and every later block, and then overtake the honest chain that keeps growing. Section 11 of the whitepaper shows that the probability of an attacker with less than half the network’s computing power catching up falls exponentially with each additional block.
Ethereum no longer uses proof of work. It switched to proof of stake at the Merge on 15 September 2022, where validators stake ETH instead of competing on hashing power. Hashes still identify blocks, link them together and secure Ethereum’s tries; what changed is how the network agrees which chain is valid.
Hashes in addresses, transactions and signatures
- Bitcoin addresses: for the classic pay-to-public-key-hash (P2PKH) format, the public key is hashed with SHA-256 and then RIPEMD-160, giving a 20-byte public key hash, as the Bitcoin transactions reference describes. Pay-to-script-hash addresses hash a script in the same way.
- Ethereum addresses: an account address is the last 20 bytes of the Keccak-256 hash of the public key, prefixed with
0x, according to ethereum.org. - Transaction IDs: every transaction is identified by its hash, so its ID changes if its content changes.
- Digital signatures: wallets sign a hash of the transaction data with the private key, and anyone can check the signature with the public key. The hash keeps the signed message short and binds the signature to the exact transaction.
- Data anchoring: businesses can store just the hash of a document or dataset on-chain and later prove the original has not changed, without publishing the data itself.
Which hash functions Bitcoin and Ethereum use
| Use | Bitcoin | Ethereum |
|---|---|---|
| Block hash | Double SHA-256 of the 80-byte header | Keccak-256 of the block header |
| Transaction summary | Merkle root (double SHA-256) | Merkle Patricia trie roots (Keccak-256) |
| Addresses | RIPEMD-160(SHA-256(public key)) for P2PKH | Last 20 bytes of Keccak-256(public key) |
| Consensus | Proof of work based on SHA-256 | Proof of stake since September 2022 |
A common point of confusion: Ethereum’s Keccak-256 is not identical to the standardised SHA3-256. NIST published SHA-3 in FIPS 202 in August 2015 with a different padding rule from the original Keccak submission that Ethereum adopted, so the two functions give different outputs for the same input. Developers who call a generic “SHA3” library when they need Ethereum’s Keccak-256 get wrong addresses and failed signature checks.
What hashing does not protect against
Hashing is one layer of blockchain security, not all of it. Be clear about its limits:
- 51% attacks: the Bitcoin whitepaper’s security assumption is that honest nodes control most of the computing power. A party with a majority of hashing power (or, in proof of stake, a large share of staked value) can reorganise recent blocks and double-spend. Hashing cannot prevent this; only the size and spread of the honest network can. Smaller proof-of-work chains are most exposed.
- Bad input: a hash proves data has not changed since it was recorded. It does not prove the data was true in the first place.
- Stolen keys and phishing: if an attacker gets a private key, their transactions are valid. Most real losses come from key theft, compromised wallets and social engineering, not broken hashes.
- Smart contract bugs: code deployed on-chain is tamper-proof, including its mistakes. Audits and testing matter more than the hash function.
- Weak or misused algorithms: security depends on using a well-studied hash function correctly. Home-made hashing schemes and mixed-up functions (such as the Keccak/SHA-3 mix-up) cause real bugs.
What about quantum computers?
The quantum risk to blockchains sits mainly with digital signatures, not hashes. NIST’s report on post-quantum cryptography (NISTIR 8105) warns that a large quantum computer could break many of the public-key systems in use today, which includes the elliptic-curve signatures that protect wallets. For hash functions, the best known quantum approach (Grover’s algorithm) gives only a quadratic speed-up, so the usual response is larger outputs rather than replacement.
At the time of writing, no quantum computer can break SHA-256 or Bitcoin’s signatures. NIST published its first post-quantum standards (FIPS 203, 204 and 205) in August 2024 and plans to remove quantum-vulnerable algorithms from its standards by 2035. Blockchain communities are discussing migration paths, and any change to signatures would need broad agreement across each network.
What this means if you are building on a blockchain
- Use well-tested libraries for hashing and signing; never write your own cryptography.
- Use the exact function the chain specifies (Keccak-256 for Ethereum, double SHA-256 for Bitcoin block and transaction IDs) and test against known values.
- Decide how many confirmations your application waits for before treating a payment as final, especially on smaller networks.
- Spend most of your security budget on key management, wallet design and smart contract audits, where real incidents happen.
- When you only need proof that a record has not changed, anchor its hash on-chain and keep the data itself off-chain.
For more on wallets, custody and tokenisation, browse our blockchain and digital assets guides.
Frequently asked questions
How does a hash help secure blockchain technology?
Every block stores the hash of the previous block, and every transaction feeds into the block’s hash through a Merkle tree. Changing any data changes the hashes and breaks the chain, so tampering is detected at once. Proof of work or proof of stake then makes rewriting the chain too costly.
Can a blockchain hash be reversed?
No. Secure hash functions are preimage-resistant: there is no practical way to find the input from the hash. That is why hashes can be published openly.
Which hash function does Bitcoin use?
Bitcoin uses SHA-256, applied twice, for block hashes, transaction IDs, Merkle trees and proof of work. Classic addresses add RIPEMD-160 on top of SHA-256 to produce a 20-byte public key hash.
Does Ethereum use SHA-3?
Ethereum uses Keccak-256, the original Keccak design. It differs from NIST’s standardised SHA3-256 in its padding, so the two give different hashes for the same input.
Will quantum computers break blockchain hashing?
Hash functions are considered far less exposed than digital signatures. The larger quantum concern is the elliptic-curve signatures that protect wallets, and NIST has already published post-quantum signature standards that networks could adopt.
Build blockchain features on a fixed price
Vibidsoft builds the software around blockchains, including wallet integrations, on-chain data anchoring, tokenisation and the APIs that connect them to your existing systems, as fixed-price projects, never by the hour. We start with a fixed-price assessment (from $1,500) that reviews your use case, chain choice and security design and ends with a fixed quote for the build; the fee is credited to the project if you go ahead.
See our custom software development services or book a free 20-minute call to talk through your project.
