How a hash is calculated
Your text is first turned into bytes (UTF-8: one byte for each plain English letter, two to four for accented letters and emoji). Both MD5 and SHA-256 then pad the message: a 1 bit, then zeros, then the message’s length, so it fills whole blocks of 512 bits (64 bytes). Each block is mixed into the running result over 64 steps of shifting, adding and combining bits. Here it is with your text:
Here it is with your numbers:
- Bytes (UTF-8) = 3
- Blocks = (3 + 8) ÷ 64, rounded down, + 1
- Blocks = 1
- SHA-256 = ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
It means your 3 bytes were padded to 64 bytes and mixed, block by block, into a 256-bit result.
The result is shown in hexadecimal: 64 digits for SHA-256’s 256 bits and 32 for MD5’s 128. Line breaks count: “abc” and “abc” followed by a new line have different hashes.
Source NIST · FIPS 180-4, Secure Hash Standard (2015) ↗IETF · RFC 1321, The MD5 Message-Digest Algorithm ↗
MD5 and SHA-256 test values
The standards print hashes of a few short messages so anyone can check a hash tool. This page gives exactly these:
| Text | Hash |
|---|---|
| “abc” | SHA-256 ba7816bf8f01cfea… |
| “abcdbcdecdefde…” | SHA-256 248d6a61d20638b8… |
| “abc” | MD5 900150983cd24fb0… |
| “message digest” | MD5 f96b697d7cb7938d… |
| empty | MD5 d41d8cd98f00b204… |
Source NIST · Example values, SHA-256 ↗
Is MD5 still safe to use?
MD5 dates from 1992. Researchers have since found ways to make two different messages with the same MD5 hash, so the IETF says MD5 must not be used where that matters, such as digital signatures. Using MD5 as a checksum against accidental errors is still acceptable. For anything to do with security, use SHA-256.
Source IETF · RFC 6151, Updated Security Considerations for MD5 ↗
FAQs
What is SHA-256?
SHA-256 is one of the Secure Hash Algorithms in NIST’s Secure Hash Standard (FIPS 180-4). It turns a message of any length into a 256-bit digest, and is called secure because finding a message that gives a chosen digest, or two messages with the same digest, is computationally infeasible.
Is SHA-256 always 64 characters?
Yes. A SHA-256 digest is always 256 bits, which is 64 hexadecimal digits, whether you hash one letter or a whole book. An MD5 digest is always 128 bits: 32 hex digits.
Is MD5 a weak hash?
For security, yes. Published attacks mean MD5 is no longer acceptable where collision resistance is required, such as digital signatures. It is still fine as a checksum to catch accidental changes, like a damaged download.
Source IETF · RFC 6151, Updated Security Considerations for MD5 ↗
What is better, SHA-256 or MD5?
SHA-256, for anything to do with security. MD5 has published collision attacks, and the IETF names SHA-256-based methods as the alternative to MD5-based ones. MD5 is shorter and still works for spotting accidental changes.
Sources
- NIST: FIPS 180-4, Secure Hash Standard (2015)
- NIST: Example values, SHA-256
- IETF: RFC 1321, The MD5 Message-Digest Algorithm
- IETF: RFC 6151, Updated Security Considerations for MD5