The dick from Cars Guide (and other HWT papers) has written several articles on it which I'm sure are published online somewhere, but the basic theory is. Each manufacturer offers up their specs, torque, revs, etc etc etc etc (and probably heaps more etcs) and from those figures the consumption calculations are made. That way all cars are done on the same test bed, with the same conditions and no interfering factors, that also means the figures are fanciful and unrealistic of all conditions. It doesn't mean they aren't achievable but it does mean they should be taken with a grain of salt.
The figures were only ever made because government regulation required each manufacturer to advertise a figure and that figure had to be done by an independent tester not the manufacturers themselves not because the manufacturers wanted to brag about how economical their cars were
Once upon a time nufti salesmen used to tell customers about how the figures were done on a closed track, that the driver was a light footed fairy and other such stupid things in all an effort to try and convince customers that if their new car didn't obtain the same figures it was because of the testing not their driving. But decent salesmen (of which are few and far between) stopped talking such shit to people and started using the truth and advising people why the figures weren't always achievable instead of blaming it on the light footed fairy.