These days, when you make a booking, you also enter your passport details at some point in the process. When you get to the airport the check in process (be it manual or automated) also scans the passport. That information then goes down a range of electronic pipes to a range of government agencies both here and at destination.
In the case of the USA (for instance) the flight cannot depart until an electronic clearance has been recieved from the USA. It also explains why you no longer have to give up the tear off bit of the entry form becuase they check you out of the country electronically.
I'll leave it up to you to guess what other countries (including the UK) do.