Mg 2+ is well known to facilitate the structural folding of RNA. However, the thermodynamic and dynamic roles of Mg 2+ in RNA folding remain elusive. Here, we exploit single-molecule fluorescence resonance energy transfer (smFRET) and isothermal titration calorimetry (ITC) to study the mechanism of Mg 2+ in facilitating the folding of thiamine pyrophosphate (TPP) riboswitch RNA. The results of smFRET identify that the presence of Mg 2+ compacts the RNA and enlarges the conformational dispersity among individual RNA molecules, resulting in a large gain of entropy. The compact yet flexible conformations triggered by Mg 2+ may help the riboswitch recognize its specific ligand and further fold. This is supported by the ITC experiments, in which the Mg 2+ -induced RNA folding is driven by entropy (Δ S ) instead of enthalpy (Δ H ). Our results complement the understanding of the Mg 2+ -induced RNA folding. The strategy developed in this work can be used to model other RNAs' folding under different conditions.