Electrifiedby vlvd.net

What Is SHA-256 and What Is It Used For? A Plain Guide

What is SHA-256? It is a hash function: it takes any input, from three letters to a whole game file, and turns it into a fixed 256-bit fingerprint, usually written as 64 hexadecimal characters. The same input always gives the same fingerprint, and changing a single byte gives a completely different one. That makes SHA-256 the standard way to check that a file has not changed, and it sits inside secure websites, software updates and Bitcoin.

You can watch it work on Tank City Reboot, a free pair of tank games that play in your browser, whose page names every game file with a short code cut from that file's SHA-256.

What is SHA-256? A simple definition

SHA stands for Secure Hash Algorithm. SHA-256 is part of the SHA-2 family, which was designed by the US National Security Agency and first published in 2001. Today it is defined in NIST's Secure Hash Standard, FIPS 180-4, which says what the digests are for in one line: to detect whether a message has changed since its digest was made. The 256 is the size of the output in bits.

A hash is not encryption. Encryption scrambles data so that someone with the key can get it back. A hash has no key and throws information away on purpose, so the output cannot be turned back into the input. If you want the general idea first, read what a hash function is.

Here is the SHA-256 of the three letters abc:

ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad

And here is the SHA-256 of nothing at all, an empty input:

e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

Both are exactly 64 characters, and a file of several megabytes gives 64 characters too. Each character is one hex digit standing for 4 bits, and 64 times 4 is 256. Our guide to hexadecimal explains why programmers write bits this way.

How SHA-256 works, in outline

You do not need the maths to use SHA-256, but the outline shows why the output looks so random.

  1. Pad the input. Add a 1 bit, then zeros, then the input's length, until the total is a multiple of 512 bits.
  2. Cut it into blocks. Each block is 512 bits, which is 64 bytes.
  3. Start from fixed values. The starting state is eight 32-bit words taken from the square roots of the first 8 prime numbers.
  4. Mix each block in 64 rounds. Each round stirs in part of the block and one of 64 constants, taken from the cube roots of the first 64 primes, using additions, rotations and bit operations.
  5. Carry the state forward. The result of one block is the starting point for the next, and the state after the last block is the 256-bit hash.

Using square and cube roots of primes is a way of saying "these constants were not picked to hide a trick". Anyone can recompute them.

The properties that make SHA-256 useful

  • Same input, same output. Any machine, any day, gives the same 64 characters for the same bytes. That is what makes comparing hashes meaningful.
  • Fixed size. Three letters and a whole file both give 256 bits.
  • One way. From a hash, the only known way back is to guess inputs and hash each guess.
  • Collision resistant. It should be impractical to find two different inputs with the same hash. Published attacks only work on cut-down versions with fewer rounds; none reaches the full 64 rounds.
  • Every byte counts. Change one character and the output changes beyond recognition. abc gives ba7816bf..., while abc with a newline after it gives edeaaff3....

One way does not mean unguessable. If the input is short or common, someone can hash likely guesses until one matches. A hash only hides an input that is hard to guess.

What SHA-256 is used for

  • Checking downloads. Download pages often list a SHA-256 next to each file. You hash your copy and compare. Debian, for example, uses SHA-256 to let you verify its software images.
  • Secure connections. SHA-2 is built into TLS, the protocol behind HTTPS, and into SSH and PGP.
  • Pinning web files. With Subresource Integrity, a page gives the hash a script or stylesheet must match, so the browser refuses a file that was changed on the way.
  • Bitcoin. Bitcoin uses SHA-256 in its proof of work: finding a hash that meets the target takes huge numbers of tries, while checking one takes a single hash.
  • Naming files by their content. If a file's name includes its hash, a new version gets a new name by itself. The next section shows this on a live page.

A worked example: version codes on a live game page

Open the Tank City Reboot page source and you will see each game file named with a ?v= code. On 6 November 2026 the first game's four files were:

  • game.loader.js?v=9f3deb030f
  • game.framework.js.unityweb?v=b5dbdd9104
  • game.wasm.unityweb?v=dbc9a0ce83
  • game.data.unityweb?v=eb80ee1dc0

Download the loader (41,121 bytes) and hash it, and the SHA-256 starts 9f3deb030fe85fce. The framework file's hash starts b5dbdd91047c. Each code is the first 10 hex characters of the file's own SHA-256.

Diagram of a game file going through SHA-256 to a 64 character digest whose first 10 characters become its version code, and how adding one space changes the digest and the address

One extra space in the file gives a new digest, a new code and a new address.

Why bother? The page itself is cached for 5 minutes (max-age=300), while the game files are cached for 30 days (max-age=2592000). Your browser keeps the big files for a month. When a file changes, its hash changes, so its address changes, and once the page refreshes the browser fetches the new file. Nobody has to remember to bump a version number by hand. Our post on cache busting walks through the caching side.

The second game, Tank City Zero Day, keeps its files in their own folder with their own codes (its framework is 8be272f8ea). Its loader, though, has the same code as the first game's, 9f3deb030f. That is the "same input, same output" rule at work: the same loader file gives the same hash, so it gets the same name.

Ten characters are 40 bits, which is plenty to tell versions of a file apart. To prove a download is genuine you compare all 64.

How to compute a SHA-256 hash yourself

On Linux, hash a file with sha256sum file.iso, or a piece of text with printf 'abc' | sha256sum. You should get the ba7816bf hash shown above.

A common mistake is echo abc | sha256sum. echo adds a newline, so you hash four bytes, not three, and get edeaaff3.... When two hashes should match and do not, look for hidden newlines, spaces and line endings first.

In a browser, the Web Crypto API does the same job. MDN's digest page shows the call: crypto.subtle.digest("SHA-256", data), which returns a promise of 32 bytes. It also warns that SHA-1, the older 160-bit hash, is now considered vulnerable and should not be used for cryptography.

Try the whole loop in five steps:

  1. Open the game page and your browser's developer tools on the Network tab.
  2. Press Play. The page loads the game files only after Play or Full screen is pressed.
  3. Find the loader request and note its ?v= code.
  4. Save that file and run sha256sum on it.
  5. Compare the first 10 characters with the code. They match.

Frequently asked questions

Can SHA-256 be decrypted or reversed?

No. SHA-256 has no key, so there is nothing to decrypt. When a hash is "cracked", someone guessed the input and hashed the guess to get a match, which only works for short or common inputs.

Is SHA-256 still secure?

Yes. It is part of NIST's current Secure Hash Standard, and published attacks only break versions with fewer than the full 64 rounds.

Why is a SHA-256 hash 64 characters long?

The output is 256 bits, and each hexadecimal character stands for 4 bits, so it takes 64 characters to write it out.

Is a 10 character hash prefix safe?

It is enough to give each version of a file its own name, which is all a cache code needs. It is not enough to prove a file is genuine; for that, compare the full hash.

Get started: play Tank City Reboot

When you are done hashing, try the game itself. Your antivirus tank guards the CPU core at the bottom of a circuit board, and malware tanks named Worm, Trojan, Spyware and Rootkit roll in, each with a one-line explanation of the real idea. Zero Day adds 8-way moves, dashes, upgrades and a boss every fifth wave.

Play Tank City Reboot: it is free, plays in your browser on a computer or a phone, and needs no account.

The Family Computer tank classic, rebuilt inside a computer.

Visit tankcityreboot.vlvd.net
Tank City Reboot on desktop
Tank City Reboot on tablet
Tank City Reboot on phone
0 likes

Comments

No comments yet.

or make an account to comment.