As I understand it, you apply broadly (sometimes in different specialties) and see who gives you interviews. From those interviews rank your top programs in order, taking into consideration your chances (by this point almost all have narrowed it down to 1 specialty).
The programs also rank the people they interviewed. The data from all the programs is put into the computer and an algorithm compares your list to the program lists. And this is your match.
If you don't match you can 'scramble' and find a program with open spots but generally the best spots are already taken.
There is one main match but some specialties have earlier matches.