Using the
Guide Number (GN) of the flash unit :
GN = distance × f-number
and using some basic algebra:
Distance = f-number / GN
f-number = Distance / GN
Keith's info above helps establish the correct flash exposure. BTW the "distance" is the distance from the flash -- not distance from the camera. "Guide number" is based on the flash being used at ISO 100 and with no flash modifiers (e.g. if you put the flash in a modifier... a shoot-through umbrella, a soft-box, etc. then the fabric is going to "eat" some of your light.)
If you use modifiers (suppose you use a shoot-through umbrella) then you'd want to find out how much the modifier alters the exposure. e.g. test the modifier by comparing shots taken both without and then with the modifier (using otherwise identical exposure settings) to determine how much light you lose with the modifier. This is important because as soon as you start working heavily with flash, you'll quickly realize you probably prefer the look of softened light (hence, you'll be using modifiers of some type.) I use a hand-held "incident" light meter (Sekonic) to work this out with precision and it really helps to have a hand-held meter that handles flash exposures -- it eliminates the guesswork. (A Sekonic L-308s would be probably the most basic model that can meter for flash.) But you can work it out even without a meter.
Also you can vary the power output of most flash units (e.g. full, 1/2, 1/4, etc. power levels) and the guide number assumes full power. If you cut the power level by 1/2 then you'd need to compensate for that (e.g. open the aperture or increase the ISO).
Next...
Notice that Keith's equations don't mention shutter speed? That's because as long as the camera uses a shutter speed which does not exceed the camera's flash sync speed, the shutter speed won't affect the exposure (assuming no strong continuous source of light on the subject -- but that's usually true.) The flash is only bright for a split second... regardless of how long the shutter remains open it won't provide any more light than you got out of that initial burst.
So once you've worked out a correct "flash" exposure for your subject... you can collect light for the background (ambient lighting) by extended the amount of time that your shutter is open. This assumes the background is DIMMER than the lighting on your main subject (provided by your flash). In other words... if you needed a 1/200th sec exposure at f/8 for your main subject (I'm just making those values up) but the background is dimmer and you want to get some background in the shot, you can leave the shutter open longer (e.g. say... 1/60th sec -- again, I'm just making this up for the example) and that would let the camera collect about three times more light from the background than it would otherwise get if you just used 1/200th. It would have no noticeable effect on your main subject (lit by your flash) UNLESS there are other "strong" continuous sources of light on that main subject.
This technique is often referred to as "dragging the shutter" (leaving it open longer than necessary for just the exposure of the main subject... so that you can also expose for the background which was not illuminated by the flash.)
Most of the time (with indoor shooting) this is the problem... if there were plenty of available light, you probably wouldn't bother with the flash. So you probably need to increase the amount of time that the shutter is open to get a more pleasing background exposure.
But there is a possibility of the opposite situation happening too ... so this general process of "dragging the shutter" won't work when the reverse is true. What if the background is well lit... but the subject is not well lit? Suppose you are shooting a subject outdoors... and your subject is in the shade of a tree, but the background is in full sun. Now the situation is reversed... an exposure for your subject will over-expose the background. And the exposure set correctly for the background will result with an underexposed foreground subject. In this situation you set the camera to expose for the background (keeping the shutter speed at or below the max flash sync speed) and then supplement with flash to boost light on your foreground subject.
All of this is really just a "taste" of what you'll want to learn. There are more scenarios... suppose the background (back indoors again) is lit with incandescent lighting. That light puts out a rather yellow/orange color cast. But the flash puts out a "daylight" color (closer to a true "white"). You can end up with a situation where the subject looks right and the background looks orange because the color of the light sources (flash vs. ambient) are not the same "color". So you fix that by putting a "gel" on the flash (the gel has a bit of an orange tint.) This matches the color of the flash to the background and now you can use white balance controls (either on camera or on the computer) to correct and the color of the room will match throughout.
All of these are issues you run into when you deal with "mixed lighting".
We can't summarize everything in one post. strobist.blogspot.com is a good website (lots of articles). There are some great books on the topic -- specifically books on the use of "flash" photography.