Buck converter with feedback loop
A buck duty cycle is fundamentally defined by Vout / Vin. If you have 12V in and 5V out, 5 / 12 ~= 0.416 which is 41.6 percent.

The error amplifier compares a sample of the output voltage (usually with some frequency compensation) to a fixed, precise reference voltage. This is what is referred to as the error signal.

If the output voltage goes high for some reason, the error signal will cause the PWM to reduce duty cycle in an attempt to bring the error to zero.

If the output voltage goes low for some reason, the error signal will cause the PWM to increase duty cycle in an attempt to bring the error to zero.

If the output voltage matches the reference voltage, the duty cycle will be as per the above formula (which is a first-order approximation; losses and delays will add some extra duty cycle to the result.)