What Is a Hash? Hash Functions and Cryptocurrency Mining

Hash: A function that converts an input of letters and numbers into an encrypted output of a fixed length.

Investopedia / Zoe Hansen

What Is a Hash?

A hash is a mathematical function that converts an input of arbitrary length into an encrypted output of a fixed length. Thus, regardless of the original amount of data or file size involved, its unique hash will always be the same size. Moreover, secure hashes cannot be "reverse-engineered" to get the input from the hashed output, at least with current technology.

If you use a specific function on the same data, its hash will be identical, so you can validate that the data is the same (i.e., unaltered) if you already know its hash. A different function would deliver a different hash.

Hashing is essential to cryptocurrency and blockchain security.

Key Takeaways

  • A hash is a function that meets the encrypted demands needed to secure information.
  • Hashes are one of the backbones of the blockchain network.
  • A hash is created based on the information sent through the function.
  • In cryptocurrency blockchains, hashes are deterministic hexadecimal numbers.

How Hashes Work

Typical hash functions take inputs of variable lengths to return outputs of a fixed length. A cryptographic hash function combines the message-passing capabilities of hash functions with security properties. Hash functions are algorithms that determine how information is encrypted.

For example, Secure Hashing Algorithm 256 (SHA-256) goes through a process to encrypt the input it receives by:

  • Converting it to binary
  • Creating hash values
  • Initializing constants
  • Chunking data into bits
  • Creating a message schedule
  • Running a compression loop
  • Modifying the final values

Using SHA-256, the word "Hello" will produce an output that is the same number of characters (64) as "Hello world" and "Hello John." However, the hash will be significantly different for all three—keep in mind that capital letters change the hash also:

  • Hello: 185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969
  • Hello world: 64ec88ca00b268e5ba1a35678a1b5316d212f4f366b2477232534a8aeca37f3c
  • Hello John: a8119595d77342cc73c93697a7f70920d3f4ded5d458e31907607e997ff76868

The function used to generate the hash is deterministic, meaning it will produce the same result each time the same input is used. While SHA 256 can generate a hashed output in milliseconds with very little computing power, it makes determining the input difficult.

Not all cryptocurrencies use SHA 256. Keccak256, Equihash, Scrypt, Ethash, and Blake3 are also examples of hashing functions used.

This makes hashing ideal for securing cryptocurrency because it would take thousands of years to reverse the encryption to determine the original input with modern technology.

Hash functions are commonly used data structures in computing systems for tasks such as checking the integrity of messages and authenticating information. Cryptographic hash functions add security features, making detecting the contents of a message or information more difficult.

In particular, cryptographic hash functions exhibit these three properties:

  • They are collision-free: This means that no two different input hashes should map to the same output hash. 
  • They can be hidden: It is difficult to guess the input value for a hash function from its output. 
  • They should be puzzle-friendly: It should be difficult to select an input that provides a predefined output. Thus, the input should be selected from a distribution that's as wide as possible. 

Because of the features of a hash, they are used extensively in online security—from protecting passwords to detecting data breaches to checking the integrity of a downloaded file.

Hashing and Blockchains

The backbone of a cryptocurrency is the blockchain, which is a globally distributed ledger formed by linking together individual blocks (files) of transaction data and information through hashing.

Blockchains only contain transactions that are validated. Validation is completed by comparing hashes, which prevents fraudulent transactions and double-spending.

Bitcoin Hashing

Cryptocurrencies use hashes in different ways. For instance, miners solve Bitcoin's hash problem by using the data in a block as input and generating a hash.

The goal is to generate a hash that is equal to or less than the network's target hash. The mining program adjusts variable numbers until it generates a hash less than or equal to the target hash.

Once the problem is solved, each node compares the block header by hashing it twice and comparing its result to the new block's hash.

What Is the Main Purpose of Hash?

Hashes have many purposes. In a blockchain, they serve as a way to compare data and secure it. For an enterprise purpose, it could be used to compress data for storage purposes.

What Is the Simplest Hash Function?

The mid square method is one of the simplest. You square a number and use the middle two digits as the hash. For example, squaring the number 61 gives you the result 3721. The hash would be 72, the middles two numbers.

What Is a Hash in Cryptography?

A hash is a mathematical function that converts a variable input to a deterministic hexadecimal number.

The Bottom Line

In a cryptocurrency blockchain, a hash is a deterministic hexadecimal number. This means that no matter how many characters the input has, the hash will always be the same number of characters. For instance, Bitcoin's hashes are always 64 digits.

Hashes are used to secure information—in the case of cryptocurrency, they are used to ensure data contained in the blocks on a blockchain are not altered. The information encrypted by the hashing function is validated by network participants when they attempt to generate a hash less than the network target. Once the target hash is reached, the network closes the block—consensus is reached after the block closes because the network continues to validate transactions and block information after the hash solution is found.

The comments, opinions, and analyses expressed on Investopedia are for informational purposes online. Read our warranty and liability disclaimer for more info.

Article Sources
Investopedia requires writers to use primary sources to support their work. These include white papers, government data, original reporting, and interviews with industry experts. We also reference original research from other reputable publishers where appropriate. You can learn more about the standards we follow in producing accurate, unbiased content in our editorial policy.
  1. Movable Type Scripts. “SHA-256 Cryptographic Hash Algorithm.”

  2. Boot.Dev. “What Is SHA-256?.”

  3. National Institute of Standards and Technology. “Cryptographic Hash Function,” Page 4.

Take the Next Step to Invest
×
The offers that appear in this table are from partnerships from which Investopedia receives compensation. This compensation may impact how and where listings appear. Investopedia does not include all offers available in the marketplace.