Accurate predictions of DNA stability in physiological and enzyme buffers are important for the design of many biological and biochemical assays. We therefore investigated the effects of magnesium, potassium, sodium, Tris ions, and deoxynucleoside triphosphates on melting profiles of duplex DNA oligomers and collected large melting data sets. An empirical correction function was developed that predicts melting temperatures, transition enthalpies, entropies, and free energies in buffers containing magnesium and monovalent cations. The new correction function significantly improves the accuracy of predictions and accounts for ion concentration, G-C base pair content, and length of the oligonucleotides. The competitive effects of potassium and magnesium ions were characterized. If the concentration ratio of [Mg2+]0.5/[Mon+] is less than 0.22 M-1/2, monovalent ions (K+, Na+) are dominant. Effects of magnesium ions dominate and determine duplex stability at higher ratios. Typical reaction conditions for PCR and DNA sequencing (1.5-5 mM magnesium and 20-100 mM monovalent cations) fall within this range. Conditions were identified where monovalent and divalent cations compete and their stability effects are more complex. When duplexes denature, some of the Mg2+ ions associated with the DNA are released. The number of released magnesium ions per phosphate charge is sequence dependent and decreases surprisingly with increasing oligonucleotide length.