The sway bar isn't really a sway bar-at least not in a race car. It doesn't control sway like it might have on your grandmother's old Essex.
The first thing to understand about a sway bar is that it is actually a torsion bar laid across the car. It connects the suspensions on each side so that when one side acts, the other side reacts. It can be found at either end of the car, although the sway bar is usually seen only on the front of short-track stock cars. While the sway bar doesn't have anything to do with sway, it is one of several items that provide some control over weight shift when the car tilts to the right in a left turn.
The function of a sway bar is usually to prevent weight transfer from one side to the other in cornering situations. By preventing weight transfer, the inside wheel in a corner maintains more of its static weight.
This very attribute of the sway bar often limits its use to paved track racing. On dirt tracks, the stock cars usually need to transfer weight to the right front to load the right-front tire enough to make it grip the loose surface. Therefore, a sway bar would detract from the handling.
A sway bar is often used on the front of a paved track race car. In this situation, the available traction favors both left and right tires being equally loaded. The sway bar provides an automatic adjustment of weight. As the chassis rolls to the right, the sway bar tries to lift the left wheel, thus somewhat equalizing the weight between the two.
Here is what happens. The sway bar connects the suspension on both sides. This is not a rigid connection. The sway bar floats in bushings mounted to the chassis. Then, each end is connected to a suspension member, usually a lower control arm. The control arm connection is accomplished with links that allow the sway bar to adapt to the changing angles as the suspension moves.
Now, in a left turn, the chassis rolls (or leans) to the right. The right wheel goes up in relation to the chassis. As the right wheel goes up, it tries to lift the left wheel through the action of the sway bar. Therefore, the weight that the sway bar lifts on the left wheel is weight that doesn't transfer to the right side. This aids in controlling the weight shift during cornering.
With a sway bar able to control the weight shift, it would be easy to come to the conclusion that we could make a rigid bar and bolt it to the lower control arms and stop all the weight shift. That won't work. The bar could never be totally rigid, and neither could the chassis. Furthermore, we don't want to stop the entire weight shift, but we want to control it. Control in this case means allowing only the weight shift that balances the right side tire traction against the left.
A certain amount of weight must be transferred to the right front to give it the traction to get the car into a turn. It is this balance that lets the left side contribute to the turning force, too. This balance often is a critical factor in handling.

This shows the sway bar in...

This shows the sway bar in torsion, with the right wheel pulling on the left. This is the situation that develops when the car rolls heavily to the right as it does in a left turn. The right-side suspension is feeding a load to the sway bar to try to lift the left. As the bar diameter is increased, the right will have more influence over the left.

Notice that the ends of the...

Notice that the ends of the bar are both high. The fact that the wheels stay the same distance from the ground indicates that the chassis has hit a dip evenly. So, with the wheels on the ground, the chassis will have dropped. Evenly loaded, the sway bar has no effect on weight transfer.

Shortening this link will...

Shortening this link will give more crossweight by pulling up on the left front and transferring the weight to the rightA front view of a car with a sway bar with links to the lower control arms. Graphic by Sharon Tender

Side view of the sway bar...

Side view of the sway bar mounting at the front of the car. Graphic by SharonTender