Divalent cations are often required to fold RNA, which is a highly charged polyanion. Condensation of ions, such as Mg2+ or Ca2+, in the vicinity of RNA renormalizes the effective charges on the phosphate groups, thus minimizing the intra RNA electrostatic repulsion. The prevailing view is that divalent ions bind diffusively in a non-specific manner. In sharp contrast, we arrive at the exact opposite conclusion using a theory for the interaction of ions with the phosphate groups using RISM theory in conjunction with simulations based on an accurate Three Interaction Site RNA model. The divalent ions bind in a nucleotide-specific manner using either the inner (partially dehydrated) or outer (fully hydrated) shell coordination. The high charge density Mg2+ ion has a preference to bind to the outer shell whereas the opposite is the case for Ca2+. Surprisingly, we find that bridging interactions, involving ions that are coordinated to two or more phosphate groups, play a crucial role in maintaining the integrity of the folded state. Their importance could become increasingly prominent as the size of the RNA increases. Because the modes of interaction of divalent ions with DNA are likely to be similar, we propose that specific inner and outer shell coordination could play a role in DNA condensation, and perhaps genome organization as well.