Like most things automotive, exhaust header and system design is a science unto itself. You could use empirical data gathered from others to determine the best possible header primary length and diameter -- and this is probably the easiest way -- or you could calculate it yourself given some basic information about your engine combo.
Header primary tube tuning has two basic parameters: airflow requirement and exhaust pulse tuning. Tubing diameter is dictated by flow requirement, which in itself is determined by engine displacement, engine rpm and the addition of a supercharger, turbo or nitrous. Header primary length has to do with timing the exhaust pulses so that the exhaust from one primary helps to suck the gases from an adjacent cylinder. There are a number of different "established" formulas, and each offers a different level of precision and application specialisation.
Adjusting displacement for boost
This is something that most formulas don't account for, but it's vital if you're using a turbo, supercharger or nitrous. Most formulas (including the one given here) use raw cylinder displacement, but actual displacement depends on volumetric efficiency (how much fuel-air charge gets used vs the engine's displacement). First, divide the engine's total displacement by the number of cylinders to get the cylinder displacement. Then, multiply that by 0.80 for a typical street engine or 0.90 for a tuned race engine. For boost pressures under 96.5 kpa (14 psi), calculate using the exact displacement. For boost levels over 96.5 kpa (14 psi), divide the actual boost level by 96.5 and multiply that by the displacement.
Adjusting displacement for nitrous
Nitrous is a bit easier, since exhaust requirements go up linearly with the amount of nitrous. First, divide the nitrous kit's horsepower level by the engine's horsepower without nitrous. Then add that figure to your volumetric efficiency (0.80, 0.90 or whatever the boost turns out to be if you're running a supercharger with nitrous). Multiply your nitrous-adjusted volumetric efficiency by the individual cylinder's displacement (engine displacement divided by cylinder count) to arrive at your final adjusted cylinder displacement.
Calculating pipe length
Look at your camshaft specs and find out how long the exhaust valve opens in degrees at 1.2 cm (0.50 inch) lift. Subtract this number from 360, then multiply that by 850 (we'll call this Figure A). If your engine sees mainly street duty, subtract 3 from the rpm at which peak torque occurs. For a race engine, subtract 3 from the rpm at which peak horsepower occurs. We'll call this Figure B. Then, divide Figure A by Figure B and you have the pipe length in inches. The formula looks like this: ((850 x (360-EVO))/rpm -- 3 where "EVO" equals "Exhaust Valve Open duration at 1.2 cm (0.50 inch) lift."
Multiply your Volumetric Efficiency-adjust single cylinder displacement by 16.38; we'll call this Figure C. Add 3 to your calculated length from Step 4, then multiply that by 25; this is Figure D. Divide Figure C by Figure D and you'll have the header tubes' inside diameter in inches. Multiply that figure by 2.5 to get the diameter in centimetres.
Example one -- mild 350
For this example, we'll use a 5,730 cc (350 cubic inch), naturally aspirated street V-8. The exhaust duration at 0.50 checks in at 212 degrees, and peak torque occurs at 2,800 rpm. Being a street engine, it has a volumetric efficiency of 0.80. We'll begin the length calculation buy subtracting 212 from 360 (equals 148), then multiply that by 850 (equals 125,800). Then we'll subtract 3 from our peak torque (equals 2,797). Dividing 125,800 by 2,797 and we end up with a final primary tube length of 44.9 inches. Mulitply that by 2.5 to get 112.25 cm.
Next, we'll adjust displacement by dividing 350 by 8 (equals 43.75 cubic inches per cylinder) and multiplying that by our 0.80 VE (equals 35). Multiply 35 by 16.38 (equals 573.3, Figure C). Now, well add 3 to our calculated header length (equals 47.9) and multiply that by 25 (equals 1,197.5) to derive Figure D. Finally, we'll divide Figure C (573.5) by Figure D (1.197.5) to arrive at an inside tubing diameter of 0.479 inch, or about 1/2 inch, which is 1.2 cm.
So, for our mild-cam, torque-heavy street 350 we'll need headers with primaries that measure about 112.25 cm (44.9 inches) long and 1.2 cm (1/2 inch) on the inside of the tube. Bear in mind that most header companies market their pipes by outside diameter; after accounting for the thickness of the metal tube, this actually comes out to about 1.8 cm (3/4 inch) outside diameter.
Example two -- supercharged and nitrous 350
While the 1.2 cm (1/2 inch) primaries given above may seem very narrow, it's appropriate for that particular engine. Lets take that same engine and add a supercharger (bumps the VE up to 1.10) and 100 horsepower worth of nitrous (adds an additional 0.25 VE for a total of 1.35), then add a longer duration camshaft (235 exhaust degrees at 0.50) and calculate header size based on the peak horsepower rpm (6,500).
Substituting these variable for those of our mild street 350, we end up with a header primary length of 40.9 cm (16.35 inches) and an inside tubing diameter of 4.9 cm (1.96 inches). Those 40.9 cm by 4.9 cm (16 1/2 inch by 2 inch) primaries line up fairly well with about what you'd expect for a full-race 350.