SHA-2 is a family of six cryptographic hashing functions widely used to facilitate digital signatures and verify file integrity. These algorithms turn any input into a fixed-length output, with even minor changes producing a completely different result. If you want to better understand this fundamental part of the internet’s security, read on. I’ll explain why SHA-2 is so important, how it works, and why we haven’t yet moved to SHA-3.

What is SHA-2?

SHA stands for Secure Hashing Algorithm, with SHA-2 being the second generation. It consists of six hashing functions: SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, and SHA-512/256. In simple terms, their job is to transform any piece of data into output of a predetermined length (called a “hash”). This doesn’t sound all that impressive, but SHA-2 has allowed us to keep the internet safe for over 20 years.
There are a few characteristics that make SHA-2 algorithms particularly useful. They’re all:

    • Deterministic: Entering a specific input will always result in the same output.
    • Cryptographic: You can’t easily deconstruct the output to find the original input value.
    • Collision-resistant: It’s extremely unlikely for two inputs to result in the same output.
    • Designed to produce the avalanche effect:  Small changes to the input result in a dramatically different output.
    • Fast: Transforming an input into an output happens almost instantly.

Diagram showing that hashes are always the same length, no matter how big the input

At the time of writing, SHA-2 is still considered highly secure. In the future, quantum computers could potentially weaken these algorithms by making it easier to find the input from a given hash. However, it’s possible to limit the risk by using an algorithm with longer hashes (such as SHA-512 instead of SHA-256). According to the European Telecommunications Standards Institute, 256-bit hashing algorithms should remain secure until “at least 2050.”

SHA-2 explained: how it works, what it’s for, and more

Below, I’ll cover everything you’ve ever wanted to know about the SHA-2 cryptographic hash functions. That said, cryptography is an extremely complex field and can quickly become overwhelming, so I’ll try to keep things simple. Comparitech also has a worked example of SHA-2 hashing in case you’re looking for a more granular breakdown.

How does SHA-2 work?

Every SHA-2 algorithm is slightly different, but their overall approach is similar. Here’s a brief, novice-friendly description of how they create near-unique hashes for any possible input.

First, SHA-2 algorithms convert your input to binary and split it into blocks of a predetermined size. If your input was larger than the block’s size, the algorithm simply creates additional blocks.

AlgorithmBlock sizeReserved space for input lengthNumber of wordsNumber of rounds
SHA-224512 bits64 bits6464
SHA-256512 bits64 bits6464
SHA-3841,024 bits128 bits8080
SHA-5121,024 bits128 bits8080
SHA 512/2241,024 bits128 bits8080
SHA 512/2561,024 bits128 bits8080

There are two golden rules. Every bit of available space must be used – empty spaces are padded until they meet the required size. Additionally, the final 64 bits of the final block are reserved for recording the length of your initial input. This increases to 128 bits if you’re using SHA-384 or higher.

Each block is then split into 16 chunks called “words”. Using complex mathematical functions, these 16 words are then expanded to either 64 or 80, depending on the chosen algorithm.

SHA-2 algorithms have eight values (let’s call them A–H) that pass results of one round to the next. These are combined with the current word and a predetermined constant value using complex mathematical functions, producing a new set of A–H values. This process repeats either 60 or 84 times per block, depending on your chosen algorithm.

Diagram explaining how SHA-256 hashing works
Diagram explaining how SHA-256 hashing works

Once complete, the starting and final A–H values are combined, creating your final hash. Finally, it’s converted to hexadecimal, meaning it only includes numbers and the letters “A” through “F”.

What are SHA-2 algorithms used for?

These algorithms, particularly SHA-256, are a vital part of what keeps us safe online. Because changing the input in any way results in a totally different hash, these algorithms can help verify whether files have been altered. The sender simply has to provide the hash of a particular file (sometimes called a checksum) so you can verify the file sent is the file you actually received.

Screenshot of an Ubuntu SHA-256 checksum
If we run the downloaded file through a SHA-256 hash calculator and it matches the checksum provided, we know it definitely hasn’t been tampered with.

Believe it or not, our collective internet security relies on the exact same technology. When you visit a website, a shield or padlock icon in the address bar lets you know the site’s secure. Website owners request certificates from a trusted certificate authority, which uses a hash of this certificate to digitally sign it. If the certificate is different when you visit the site, you’ll usually see a warning since it means something’s changed.

Screenshot of the shield icon on comparitech's website

Various cryptocurrencies, including Bitcoin, rely on SHA-2 for proof-of-work functionality. Essentially, miners continuously hash numbers until they find one that creates the desired hash. This then earns them a reward, and the process begins anew.

These are just a few real-world examples of how SHA-2 can be used. They’re also a vital part of:

Why don’t we use SHA-3?

SHA-1 was designed to replace less-secure algorithms like MD5 and remained the main cryptographic hashing function for a full decade after its release in 1995. However, its 160-bit hashes meant that an adversary with lots of time or computing power could find a collision more easily than first thought. That’s a problem because if two distinct files can produce the same hash, our whole safety-verification system falls apart.

In response, organizations began phasing out SHA-1 in favor of SHA-2, which uses 256-bit hashes. This increases the amount of computing power required to find collisions via brute-forcing, and remains the standard even today.

In 2015, the National Institute of Standards and Technology (NIST) released SHA-3. Despite the name, this algorithm has very little in common with its predecessors. For instance, it’s based on Keccak, which uses 1,600-bit blocks and can create hashes of any length.

Its advantages are that it’s more secure than SHA-2 and can be directly substituted if any new SHA-2 vulnerabilities are discovered. However, device compatibility and speed remain practical concerns. SHA-2 is still functionally impossible to break, so there’s no need to switch just yet.

Conclusion

It’s difficult to wrap your head around cryptographic concepts unless you’re already intimately familiar with mathematics. Thankfully, you don’t need to understand exactly how SHA-2 algorithms work to appreciate how useful they are. These hashing functions underpin many of our most critical digital security systems, and without them, we’d be in real trouble.

If you’re interested in learning more, check out our beginner’s guide to cryptography. We also have posts explaining preimage attacks and best practices for hashing and salting passwords.