You need to be aware of certain common sense guidelines for getting yourself set up on your bike:
NEVER take anybody's word for anything. Over the years many of my customers have been convinced they were riding a frame that was x cm or y inches in size 'because the man in the shop where I bought it from said so'. When measured, the frames have been anything up to five centimetres different!
Whereas frame sizes can be 'close enough', saddle height is a critical dimension
My experience has shown that the best way to go about setting up a bike is to get the saddle in the right position first, both vertically and fore and aft, then sort out the reach to the handlebars, and the height of the handlebars.
Frame size and saddle height bear a loose relationship, but whereas frame sizes can be 'close enough', saddle height is a critical dimension. The various formulas give starting points, but the fine-tuning must be done over a period of time spent riding the bike. What may feel fine on a stationary jig in a shop may not feel so good after half a day of riding, or when cornering, descending, climbing or riding over uneven surfaces.
There is a commonly used formula:
Inside leg + 9% = distance from pedal face to top of saddle
The principal variables that affect this are foot size and pedalling style. A rider with big feet who pedals 'pointy-toed' will need to sit higher than a rider with small feet and a flat pedalling style.
The best method to initially determine saddle height is to sit on the bike with your heels on the pedals. Pedal backwards and see if your bottom slides from side to side on the saddle (get a friend to watch you from behind). If you rock from side to side you are sitting too high. Set the saddle so that your bottom does not roll from side to side but such that your leg is straight at the bottom of the crank stroke. When pedalling you will have a slight bend at your knee when the pedal is at its furthest point (in line with the seat tube).
As a rule of thumb, set the fore and aft position of the saddle so that your kneecap is over the pedal spindle on the leading crank when horizontal. However, you may wish to adjust this by a few millimetres either way, depending on your pedalling style.
Road and touring bikes
The position of a rider on a road bike is critical
You must determine a reasonable frame size. You will note I said 'reasonable' not 'right'. Frame size is dictated as much by fashion as it is by any solid measurement. For a road bike the position of the rider on the bike is more critical because you spend far more time sitting in the saddle than on a mountain bike. A racing bike is usually smaller than an Audax or Touring bike for the same person. The bars need to be lower and the saddle slightly further forward.
A reasonable rule of thumb is to take your inside leg measurement from crutch to floor without shoes. Add 8% to this, subtract your crank length less an allowance for the type of shoes and pedals you will use (i.e. about 10mm for conventional or SPD pedals, or about 15mm if you use Look pedals). Then multiply this by a factor relevant to the bike type and how much seat pin you want showing. I use 0.82 for touring bikes and 0.77 for race bikes. This isn't gospel but gives a starting point to work from.
If we work through an example to illustrate the point:
Say a rider has an inside leg measurement of 810mm and he wants a bike for audax riding.
The rider's inside leg measurement is 810mm, add 8% = 875mm.
His cranks are 170mm, minus the depth of his pedals (SPD 10mm) = 160mm
Subtract 160 from 875 = 715mm.
As this is for an Audax frame, multiply the figure by 0.82.
715 x 0.82 = 58.63cm
All this gives us is a proposed seat tube length. Most off the peg bikes have reasonable proportions between seat and top tube, so this is a fair comparison between frames. So, if our mythical rider is looking for an off the peg bike then he (or she) needs to look for frames of around 58 - 59cm to the top of the seat lug on a conventional frame, or 56 - 57cm to the centre line of the top tube, again on a conventional frame. When seeking a frame or bike always take a tape measure with you and measure it.
So, our rider has found a shop with several bikes with seat tubes in the advised range, but all of them have different top tube lengths and worse, different handlebar stem lengths too. The horizontal distance from saddle to bars (the reach) is just as important as the saddle height. For any given top tube length, the reach can be altered by changing the length of the handlebar stem. For the style of riding this type of bike is intended for (long distance, endurance events) a fairly relaxed position is called for, not too stretched out, When sitting with the hands on the tops of the handlebars the rider's back should be at about 45 to 50 degrees to the vertical. You should be able to reach the brake levers without stretching.
One of the major problems I see when checking riders' positions is that the 'bars are too far away (stem too long) and set too low. This usually results in a pain in the neck and shoulders after riding for any length of time because the rider's head has to be held at an unnatural angle to see where he is are going! This is a long-winded way of saying our rider should try sitting on each bike with the saddle adjusted to correct height and try the reach.
Mountain bikes are different. The bike still has to fit you, but the main consideration is that you can stand over the top tube with 3 - 4 inches of clearance between the top tube and your crotch (just in case you are brought to an abrupt halt on uneven terrain!), and that when riding you are 'balanced' between the wheels with a weight distribution of about 60:40 rear to front. Your saddle height should be about the same, or marginally lower, than on a road bike.
Your handlebar position depends upon your arm length. Move the bars in the stem to get the best angle for your wrists. Set the brake and gear levers so that your hands fall naturally to them, don't just leave them where they were when you got the bike! Don't be afraid to experiment. Use the adjustment built into all the components where you touch the bike to make the bike fit you - that's why they are adjustable.
Unless your position is 'way out' it is advisable to make just small incremental changes, of about 5mm, one at a time
It is impossible to give a formula or a set of instructions that will cover all circumstances for all riders (and don't believe anyone who tells you that there is.) You'll probably need to tweak your position as you progress with your cycling over a period of months or years, and you're quite likely to have a slightly different position on depending on whether you are mountain-biking, road racing, doing a 25 mile time trial or a 400km Audax event. Unless your position is 'way out' it is advisable to make just small incremental changes, of about 5mm, one at a time. This will allow your muscles to adapt to the new position.
Also, if you alter everything and then start feeling aches, pains or twinges somewhere you won't know which alteration caused the problem. You could measure the relative position of each component and record each change, in case your adjustment causes problems and you need to revert to the original position. It is always a good idea to seek informed advice from someone who knows what they are talking about, such as a coach, established frame-builder, shop staff or experienced rider.