Mg2+ has been shown to modulate the function of riboswitches by facilitating the ligand-riboswitch interactions. The btuB riboswitch from Escherichia coli undergoes a conformational change upon binding to its ligand, coenzyme B12 (adenosyl-cobalamine, AdoCbl), and down-regulates the expression of the B12 transporter protein BtuB in order to control the cellular levels of AdoCbl. Here, we discuss the structural folding attained by the btuB riboswitch from E. coli in response to Mg2+ and how it affects the ligand binding competent conformation of the RNA. The btuB riboswitch notably adopts different conformational states depending upon the concentration of Mg2+. With the help of in-line probing, we show the existence of at least two specific conformations, one being achieved in the complete absence of Mg2+ (or low Mg2+ concentration) and the other appearing above ∼0.5 mM Mg2+. Distinct regions of the riboswitch exhibit different dissociation constants toward Mg2+, indicating a stepwise folding of the btuB RNA. Increasing the Mg2+ concentration drives the transition from one conformation toward the other. The conformational state existing above 0.5 mM Mg2+ defines the binding competent conformation of the btuB riboswitch which can productively interact with the ligand, coenzyme B12, and switch the RNA conformation. Moreover, raising the Mg2+ concentration enhances the ratio of switched RNA in the presence of AdoCbl. The lack of a AdoCbl-induced conformational switch experienced by the btuB riboswitch in the absence of Mg2+ indicates a crucial role played by Mg2+ for defining an active conformation of the riboswitch.