The interaction between metal ions, especially Mg ions, and RNA plays a critical role in RNA folding. Upon binding to RNA, a metal ion that is fully hydrated in bulk solvent can become dehydrated. Here we use molecular dynamics simulation to investigate the dehydration of bound hexahydrated Mg ions. We find that a hydrated Mg ion in the RNA groove region can involve significant dehydration in the outer hydration shell. The first or innermost hydration shell of the Mg ion, however, is retained during the simulation because of the strong ion-water electrostatic attraction. As a result, water-mediated hydrogen bonding remains an important form for Mg-RNA interaction. Analysis for ions at different binding sites shows that the most pronounced water deficiency relative to the fully hydrated state occurs at a radial distance of around 11 Å from the center of the ion. Based on the independent 200 ns molecular dynamics simulations for three different RNA structures (Protein Data Bank: 1TRA, 2TPK, and 437D), we find that Mg ions overwhelmingly dominate over monovalent ions such as Na and K in ion-RNA binding. Furthermore, application of the free energy perturbation method leads to a quantitative relationship between the Mg dehydration free energy and the local structural environment. We find that ΔΔG, the change of the Mg hydration free energy upon binding to RNA, varies linearly with the inverse distance between the Mg ion and the nearby nonbridging oxygen atoms of the phosphate groups, and ΔΔG can reach -2.0 kcal/mol and -3.0 kcal/mol for an Mg ion bound to the surface and to the groove interior, respectively. In addition, the computation results in an analytical formula for the hydration ratio as a function of the average inverse Mg-O distance. The results here might be useful for further quantitative investigations of ion-RNA interactions in RNA folding.