Take the sorted list [4, 9, 15, 22, 30, 41, 56, 63, 78], indexes 0 to 8, and look for 56. Set low = 0 and high = 8. The middle index is (0 + 8) // 2 = 4, holding 30. Since 56 > 30, the target can only be to the right, so low = 5. Now mid = (5 + 8) // 2 = 6, holding 56: found in 2 comparisons. Each comparison discards everything on one side of mid, plus mid itself.
That 'plus mid itself' matters. After checking a[mid], the new range must leave it out: low = mid + 1 or high = mid − 1. Write low = mid instead and a range of two items can stay the same size forever. The loop runs while low ≤ high; once low is greater than high, the range is empty and the answer is 'not found'. Search the same list for 50: mid 4 holds 30, go right, low = 5; mid 6 holds 56, go left, high = 5; mid 5 holds 41, go right, low = 6. Now low = 6 > high = 5, so 50 is not in the list.
Because the range halves each time, a list of n items needs at most ⌊log2n⌋+1 comparisons: 4 for 9 items, 10 for 1,000, 30 for a billion. The catch is that the list must be sorted by the same value you search for. A class list sorted by name can be binary-searched for a name, but not for a test score; finding who scored 88 needs linear search or a second list sorted by score.
Think of it like this. Binary search is how you find page 412 in a thick book: open near the middle, see whether the page number there is too high or too low, and keep only the half that must contain 412. It works because page numbers are in order; if the pages were shuffled, the number you opened to would tell you nothing.
Core idea. Each comparison eliminates half the remaining possibilities — O(log n) vs O(n) for linear search.