The quicksort algorithm works by recursively sorting arrays of data. It first selects a pivot element and partitions the array around the pivot so that all elements less than the pivot come before it and all elements greater than the pivot come after it. It then recursively sorts the sub-arrays to the left and right of the pivot until the entire array is sorted.