The binary search algorithm finds the position of a specified input value within a sorted array. It works by repeatedly dividing the search interval in half. The algorithm compares the search key value to the middle element of the array. If it matches, the position is returned. If the key is less than the middle element, the upper half is discarded and the search continues on the lower half. If it is greater, the search continues on the upper half. This continues with each half containing fewer elements until the key is found or the array is determined to not contain the key. The maximum number of comparisons required is log n, so the algorithm runs in O(log n) time.