As others have said, they use the average from many previous flights to work out the ratio. With large numbers (lets say 525 for an A380), you can tell that the actual number will come pretty close to the average.
I ran 2000 simulations in Excel, modelling a flight where they know, on average, 70% choose option A, 30% choose Option B on a 525 seat A380. The flight elects to take 404 of option A (10% more than they need on average) and 173 of option B (again, 10% spare).
The flight never ran out of option A in any of the 2000 'flights'. The flight ran out of option B 140 times (7%).
They can do better, by having a smaller % buffer on the more popular meal, due to how the law of large numbers works. Taking 15% spares on the less popular meal, and 7.8% spares on the more popular meal (which means taking 10% spare meals in total) reduces the number of times that the airline ran out of option B to 22 (1.1%), whilst still never running out of option A. There is likely further optimisation that could occur, 15% and 7.8% was the only number I tried other than the 10% for each.
This link here implies that the cabin crew (but presumably not the flight crew who have to eat different meals to each other) are made to eat whatever is not chosen by the passengers. On an A380, this is a 27 buffer out of 525 (just over 5%), so this is the minimum possible buffer an airline could use. But presumably they would at the very least have a few extra meals so that no-one goes hungry if one meal is dropped.
Assuming they bring 5 'spare meals', plus 27 for the flight crew and the flight is at 80% occupancy, that puts the buffer on meals at 32/420. However, those 420 meals for customers won't all be normal meals, but that 27 buffer is just for normal meals. Vegetarianism in the USA is 3.2%, and when you add in Gluten Free, Dairy Free and Kosher, we could easily reach 5%. That least us with a buffer of 32 out of 399, or 8%. With only 5 meals at risk of going in the bin each flight.
Results will be worse on smaller planes, which may be where conflicting anecdotal evidence from domestic short haul flights comes from.