Two methods.
One is the old-fashioned diary method. People fill out diaries on what they watched and when for a week. A bunch of people send the diaries in, and Neilsen adds the totals up.
The company also has meters that monitor what people watch and when, and electronically send the information to a central data bank. That's obviously more accurate, since there's no room for lying.