Im still applying to medical school but this is how I understand it. Basically as a 4th year you go to interviews for residency and at the end of it, you list your preferrences. The school does the same for the students that they interviewed. Then on Match Day, they cross the two lists together and send acceptances accordingly. So if Harvard was your number one choice, and you were their number one, then you'd match. If Harvard was not your first, they would go down to their number two, and so on.
Any current med students, please tell me if I have it right or wrong?