Stacking is the stabilizing interaction between the flat surfaces of adjacent bases. Stacking can happen with any face of the base, that is 5-5, 3-3, and vice versa.
Stacking in "free" nucleic acid molecules is mainly contributed by intermolecular force, specifically electrostatic attraction among aromatic rings, a process also known as pi stacking. For biological systems with water as a solvent, hydrophobic effect contributes and helps in formation of a helix. Stacking is the main stabilizing factor in the DNA double helix.
Contribution of stacking to the free energy of the molecule can be experimentally estimated by observing the bent-stacked equilibrium in nicked DNA. Such stabilization is dependent on the sequence. The extent of the stabilization varies with salt concentrations and temperature.