As far as i know the market research folk have a sample of people that answer questions every week on what TV programmes they watch what they bought in there shopping etc. For example if 10 out of 1000 people watched top of the pops they just multiply the 1000 up to the same number of the population with TVs and then they do the same with the 10. so if 50,000 in the uk have TV's the estimate thate 500 people watched Top of the pops. I know it is not a very clear answer but it is the simplest way i could think to put it.
Its sort of like that, but a bit more complicated. There are a number of households that have a special box which is attached to their TV, this picks up information about what they watch and sends in to a central office where the figures are multiplied to match the populations. Its fairly accurate but of course not totally.