Blog Post

An Animated Tutorial of the MD5 Hash Function

We've created an animated explainer that shows how the MD5 hash function works step-by-step. You can see visually what happens at each step - no need to visualize source code in your head.

If you are familiar with bitwise operations, skip to 5:52.

As a summary:

  1. The MD5 pads the input until the length is a multiple of 512 bits
  2. For each 512 bit segment, it divides the input into 32-bit words (16 segments)
  3. The MD5 begins with a hardcoded 128-bit state which is mutated based on the input values. The state is divided into 4 32-bit words.
  4. The MD5 iterates through the 16 segments 4 times each for a total of 64 iterations. On each iteration, it shuffles 3 out of four of state words, but one of the words B' is the result of combine(A, B, C, D, input[currentSegment]).
  5. The combine function computes B + rotate(F(B, C, A) + A + input[currentSegment] + K[i], r[i]). K and r are hardcoded constants.
  6. The function F is shown below: