Hash generator · Guide

MD5 Hash Algorithm: How the Digest Is Built, Step by Step

MD5 was designed by Ron Rivest in 1991 as a fast one-way function. Understanding its five steps explains both why it is so quick and why it eventually broke — the two facts turn out to be related.

Step 1 and 2 — padding and length

The message is padded so its length is 64 bits short of a multiple of 512. Padding always happens, even if the message already fits: a single 1 bit is appended, then as many 0 bits as needed.

The final 64 bits hold the original message length in bits. This is what makes hashing "abc" and "abc" plus padding produce different results — length is part of the input, not an afterthought.

Step 3 — the four-word state

MD5 keeps 128 bits of state in four 32-bit words, initialised to fixed constants. Every block of the message updates this state, and after the last block the four words concatenated are the digest.

Because the state is fixed-size, the whole message is compressed into it. That is where information is destroyed and why the function cannot be inverted — and also why collisions must exist mathematically.

Step 4 — 64 operations in four rounds

Each 512-bit block is split into sixteen 32-bit words and processed in four rounds of sixteen operations. Each round uses a different non-linear function, plus a per-step constant derived from the sine function and a per-step left rotation.

A worked example is easier to see than to describe: the empty string produces d41d8cd98f00b204e9800998ecf8427e, "abc" produces 900150983cd24fb0d6963f7d28e17f72, and "abd" — one letter different — produces 4911e516e5aa21d327512e0c8b197616. That avalanche is by design.

Why the design failed

The four rounds do not mix bits aggressively enough. In 2004 Wang and Yu published a differential attack finding collisions in hours; today the same work takes seconds, and chosen-prefix collisions let an attacker start from two meaningful documents.

Speed was the goal in 1991 and became the weakness: MD5 is fast for you and equally fast for whoever is attacking it. SHA-256 uses 64 rounds over a 256-bit state with far stronger mixing, which is why it has held up.

Frequently asked questions

How many rounds does MD5 use?

Four rounds of sixteen operations each — 64 operations per 512-bit block.

Why does MD5 pad even when the message fits?

Padding is unconditional so that the message length is always encoded unambiguously. Without it, different messages could produce identical padded blocks.

Is MD5 still fast compared to SHA-256?

Slightly, but modern CPUs have hardware SHA instructions that close the gap. Speed is no longer a reason to choose MD5.

Ready to try it?

Open the free browser-based Hash generator and apply what you just read — no sign-up, runs locally.

Open the Hash generator tool