Some applications need constant bit rate (CBR), some need variable bit rate (VBR).
Controlling the output bitrate is typically archived by measuring the rate and/or the encoder buffer fullness level and feeding this back to control the encoder. Many of the encoder parameters can affect output bitrate, like type of slice, motion searching range, mode selection algorithm. The most useful parameter for bitrate control is the quantizer parameter(QP).
One way to control bitrate is simply to try and enforce a constant number of bits per coded frame, by measuring the output bitrate and feeding it back to control QP. This method has problem because it doesn't deal with I,P,B slices separately since they generate significantly different numbers fo bit, and the image quality may be bad.
A more flexible approach is: the bitrate is used to determine a target number of bits for a Group of Pictures (GOP), typically and I slice followed a number of P/B slices. The bits available for the GOP are then allocated to I,P, and B slices, with the allocation changing depending on the slice type. I slice usually allocate more bits, followed by P slice, and then B slice. Within each slice, a certain number of bits are allocated to each macroblock. The rate control algorithm then attempts to control the encoder to produce the target number of bits. [from book H.264 Adv Video Compression Standard]