The document step-by-step demonstrates the insertion sort algorithm by running it on the sample array [30, 10, 40, 20]. It shows the state of the array and relevant variables after each iteration of the outer for loop. Each step switches the value of one element in the array to correctly sort it in ascending order. After running through all elements, the array is fully sorted as [10, 20, 30, 40].