Introduction to Hashing for New Web3 Developers
An overview of hashing, SHA-256 and how it relates to blockchains.
Hello Developers 🌱
Welcome to today’s post, where we’ll break down a blockchain topic into bite-sized pieces to help you learn and apply your new skills in the real world.
Today’s topic is Hashing.
Here’s a list of what we’ll cover 🗒
- ✅ What is a hash?
- ✅ What is SHA-256?
- ✅ Why use SHA-256?
- ✅ SHA-256 Demo
By the end of this post, you’ll have a basic understanding of hashing, hashing functions, SHA-256, and how it all relates to blockchain.
Let’s go! 🚀
✅ What is a hash?
A hash is a digital fingerprint for information. It’s a unique set of letters and numbers that represent a given set of data. To create a hash value, you pass data through a hashing function.
- Hash Value is a digital fingerprint for information.
- Hashing Function maps a group of data to a unique hash value.
A hashing function takes data and creates a completely unique hash value. This hash value now acts as an identifier you can reference to retrieve the original data. This means that no matter how complex or large the data was, you can now easily identify this information by referencing its hash value.
✅ What is SHA-256?
SHA-256 is a specific type of hashing function. SHA stands for Secure Hashing Algorithm and 256 represents the total bits for the output of the function.
In this case, 256 tells us that the value you’ll receive as a hash is a 256-bit number. A 256-bit number is a number that can store 256-bits of information. Since bits are stored in binary and it takes roughly 2–4 binary bits to create a character, this means that the resulting SHA-256 output is roughly 60–80 characters long.
Example Hash Value
a474219e5e9503c84d59500bb1bda3d9ade81e52d9fa1c234278770892a6dd74
There are many different hashing functions, but we’re focused on SHA-256 because blockchains use this to create a unique hash value for each block on a blockchain. This allows us to reference blocks by their hash value and creates the foundation from which we can join blocks together into a chain.
✅ Why use SHA-256?
Blockchains use SHA-256 because a 256-bit hash is much more secure than other common hashing algorithms. Here are some key benefits of SHA-256.
- Secure and trusted: Many industries have depended on SHA-256 and it has proven to be effective and secure.
- Collisions are unlikely: Since SHA-256 has many possible hash values, it’s very unlikely for two inputs to result in the same hash. Cases where two values do have the same hash is known as a collision.
- Avalanche effect: Even small changes in data will create a completely different hash value. This is known as an avalanche effect.
Because of these benefits, SHA-256 is an excellent choice for creating a blockchain, which we’ll discuss in more detail in a later post. For now, keep in mind that a block is a set of data that can be passed through a hashing function and assigned a hash value just like any other data.
✅ SHA-256 Demo
Here’s a look at the hashing process using this website. This site provides an interactive demonstration to show how hash values work. When you get to the site, navigate to the HASH section from the top and you should end up with a screen that looks like this.
On this page you have a place to write text and a corresponding hash value. This demonstration generates a unique hash value using SHA-256 from any text you type. Try typing something and notice how the hash value changes every time your text changes.
For example, if I type gm, I get the following hash value.
gm hash value
a474219e5e9503c84d59500bb1bda3d9ade81e52d9fa1c234278770892a6dd74
This hash is the unique value for this string of text. If you type gm you should get the exact same hash value. That’s because it’s the same text being passed through the same SHA-256 hashing function.
If anyone in the world inputs this same text they will get the exact same hash value. By adding some additional text, for example, gm blockchain, the hash becomes a completely different value.
gm blockchain hash value
1cd8c259aa03c5f40950d5919aaea43e1797f3eaf4a89de30830ba2c61e0a6d6
Changing the data slightly can result in a completely different and unrelated hash value. For that reason, a hash will provide a unique value but it is not a way to tell if the information is related in any way.
Hashing is an important concept in future posts about blocks, blockchains, and more detailed blockchain concepts. As you learn more, keep in mind that a hashing function always serves the one simple purpose of creating a unique hash value from data. This is true whether you type data in yourself, get data from somewhere else, or the data is an entire block of information stored on the blockchain.
Additional Resources
If you’d like to learn more about hashing, hashing functions, and how it relates to blockchain, you can check out some of these resources.
- How Bitcoin Works: Hashing
- What is Bitcoin Hash Rate?
- Cryptographic Hash Functions
- The Mathematics of Bitcoin — SHA-256
Follow for future posts where we explain topics like these in more detail!
Congratulations 🎉
That wraps up today’s topic on Hashing. You can review each of the items we covered below and check that you’re ready to apply these new skills.
Here’s a quick review of what we covered 🤔
- ✅ What is a hash?
- ✅ What is SHA-256?
- ✅ Why use SHA-256?
- ✅ SHA-256 Demo
Hopefully, you now have a basic understanding of hashing, how it relates to blockchains and are be more familiar with SHA-256.
GN! 👋