Free-living nitrogen fixation (FLNF) is a ubiquitous and significant source of new nitrogen in ecosystems. This process requires a substantial amount of energy, and as a result, the input of labile carbon to soils may enhance FLNF. Here, we aim to explore the precise influence of different types and quantities of carbon on FLNF. We conducted experiments where sugars, carboxylic acids, and amino acids (common labile carbon inputs via root exudates) were added to cropland and forest soils. We monitored the changes in FLNF rate and diazotrophic community in response to these additions. Our findings revealed that sugars and carboxylic acids significantly stimulated FLNF rate, with an increase of up to three orders of magnitude, while amino acids either restricted FLNF or had no effect. When a mixture of sugars and carboxylic acids was added, the stimulation of FLNF was not observed until a threshold quantity of carbon was reached, indicating competition between diazotrophs and other microbes. Furthermore, the enhanced FLNF rate following carbon addition was attributable to shifts in diazotrophic community composition (e.g., increased abundance of Paenibacillus, a genus frequently used as biofertilizers), rather than to changes in the overall abundance of diazotrophs (reflected by nifH gene copy number). Our findings highlight the significant role of carbon type and quantity in regulating soil FLNF, partly through restructuring the diazotrophic community. The results have implications for predicting the response of rhizosphere FLNF to shifts in root exudation under environmental changes and can contribute to the application of diazotrophic biofertilizers in sustainable agriculture.