**hashing**.

Hashing is a cryptographic function that converts a string of characters of any length into a unique **output**, or **hash**, of fixed length. This means that no matter what combination of symbols are used as the **input**, they will always produce a one-of-a-kind **string of digits and characters**.

A Bitcoin hash looks like this:

00000000000000000025e2ba026a8ad462b9a693d80fd0887def167f5f888a11

(hash of block 540807)

HASHING ESSENTIALS

- Hashing is a method for cryptographically encoding data.
- It produces a fixed-length output from any input.
- The same input always produces the same hash.
- The input cannot be reconstructed from the hash.
- Modern hash functions make it virtually impossible to produce the same output from two different inputs.

## Hashing in cryptocurrencies

Hashing is an integral part of all blockchain-based transactions, including the trading of cryptocurrency. Hash functions are necessary in everything from mining blocks to signing transactions to generating private keys.

Bitcoin | Bitcoin Cash | Ethereum | Litecoin | Ripple |

SHA-256 | SHA-256 | keccak256 | scrypt | SHA-512 |

A hash function is a mathematical algorithm used to calculate the hash. Different cryptocurrencies use different hash functions but all of them follow the same basic principles of hashing.

## Main properties of hashing

### Hashing produces outputs of fixed length

Hashing will always produce a unique, fixed-length output from any input. Let us take a look at what that means with a couple of examples.

Input | Output |

hello | 2CF24DBA5FB0A30E26E83B2AC5B9E29E1B161E5C1FA7425E73043362938B9824 |

It’s a good day to HODL. | 6B89D5D4AD6A3364410DD9BAB95FD250EF4A663D9D3C47CBD7388535A5912E03 |

The entire novel Bleak House by Charles Dickens | 4F144CC612CA27E2DD6DFD6663F68BABC3B758D602B5102BF14E717E823EB741 |

In the table above, the SHA-256 hash function is used to generate the hashes of three different inputs. In all three cases, the hash is completely unique, but its length remains the same. SHA-256 generates hashes that are 256 bits long, usually represented as 64 symbols comprised of numbers 0–9 and letters A–F. No matter how short or how long the input is – be it a single word (hello) or even a whole novel (*Bleak House* by Charles Dickens) – the hash is fixed at 64 characters.

### Hashing is deterministic

The same input will always produce the same output. If you use SHA-256 to generate a hash from “fun”, you will always get the output seen in the table below. Even changing one letter, however, will produce a completely different hash.

Input | Output |

fun | 00C4285274FCC5D6FBA2EE58DAF0D8C2B9B825B68D35D65D0E90A9BB333A51B5 |

sun | 27756F050E14A1CB1C1EE867F0EACE9EA4D9FCB81B8BEE089469F1EBD5FD7B17 |

### Hashing is a one-way function

It is **infeasible** to determine what the input was from any given output. That is to say, it is virtually impossible to reverse the hash function with contemporary technology. The only way to determine what the input was is trying out random strings until you find the right one. This method is known as **brute force**.

Using brute force to reverse the hash back to the original string is easier said than done. No computer in existence is powerful enough to find the solution in any reasonable amount of time, nor are we ever likely to build one that will. Even IBM Summit, currently the fastest computer in the world, capable of making several trillion calculations per second, would need many years and an astounding amount of electricity to find the answer for a single hash.

### Hashing is resistant to collisions

A **collision **occurs when a hashing mechanism produces the same output for two different inputs. This is possible in theory for hashing, as the number of unique hashes is limited but the number of inputs is not. However, the probability of collisions is extremely small. Hashing is thus said to be *resistant*, but not *immune*, to collisions.

SHA-256, the algorithm used by Bitcoin, outputs hashes that are 256 bits long (a 256 digit-long string of 1s and 0s). This means there are a total of 2256 unique hashes that it can produce. As soon as the number of inputs is larger than the number of all possible outputs, let us say 2256+1, at least two of the inputs will have the same output – that’s a collision.

So does that mean hashing is exploitable? No, not at all. 2256 is an enormous number. In fact, enormous does not even begin to do it justice. Think about it this way: 2256 is very roughly equal to the number of atoms in the entire observable universe. The sheer size of this number means the likelihood of a collision occurring is utterly miniscule.

## Hashing is fundamental for blockchain

Blockchain technology combines a range of important solutions from various fields of science. The cryptographic hash function serves as the basis for building a blockchain and harnessing those solutions. It is difficult to imagine a decentralized network that forgoes hashing entirely.