The bubble sort algorithm repeatedly steps through a list of items, compares adjacent pairs of items, and swaps them if they are in the wrong order. This process is repeated in passes through the list until it is fully sorted from lowest to highest value. The example demonstrates sorting the array [5, 1, 4, 2, 8] using bubble sort in three passes, with swaps occurring on the first two passes until the list is sorted after the third pass.