# Hash Function

**tl;dr:** A hash function is a mathematical function that produces a fixed-size output, unique to the input. Hash functions are commonly used to verify the integrity of data and to provide a tamper-proof record of transactions. They are designed to be one-way functions, meaning it is difficult to determine the original input from the hash value. Bitcoin uses a cryptographic hash function called SHA-256.

## What Is a Hash Function?

A hash function is a mathematical function that takes an input of any size and produces a fixed-size output, called a hash or hash value. The hash value is unique to the input, meaning that even a small change to the input will produce a completely different hash value. Hash functions are commonly used in computer science and cryptography to verify the integrity of data, to encrypt passwords, to ensure secure communication, and to provide a tamper-proof record of transactions.

Hash functions are designed to be one-way functions. This means that it is computationally infeasible to reverse-engineer the original input from the hash value. In other words, given a hash value, it should be very difficult to determine the original input that produced it. This is an important property for many applications, including password hashing and digital signatures, where it is crucial to protect the original data from being exposed.

### Example of a Basic Hash Function

A example of a basic hash function is the modulo operator, which takes two numbers and returns the remainder when the first number is divided by the second number. For instance, if we apply the modulo operator with the numbers 7 and 3, we get a hash value of 1 because 7 divided by 3 leaves a remainder of 1.

### Hash Functions in the Context of Bitcoin

In the context of Bitcoin, hash functions are used to secure the network and ensure the integrity of the Bitcoin blockchain. In particular, Bitcoin uses a cryptographic hash function called SHA-256 to hash blocks of transaction data together in a way that is mathematically difficult to reverse.^{[1]} Each block in the Bitcoin blockchain contains a hash of the previous block, which creates a chain of blocks that cannot be altered without changing the entire chain. This provides a tamper-proof record of all Bitcoin transactions and ensures the security and validity of the Bitcoin network.