The knotting probability of a closed chain has been calculated as a function of chain dimensions and solvent properties in a number of studies. We have measured the probability of DNA knot formation upon random cyclization of linear DNA in vitro to provide an experimental test of the various theoretical treatments of the problem; parameters of these models, such as the effective chain diameter of DNA, were calculated in different concentrations of counterions. Our results in the presence of sodium ions agree well with theoretical treatments of DNA as a polyelectrolyte; knotting data in the presence of divalent magnesium ions indicate that moderate concentrations of magnesium ions can induce an attractive potential between DNA segments, resulting in negative values of the calculated effective DNA helix diameter. We discuss structures in which the divalent magnesium counterion facilitates the close apposition of two DNA segments, and review the effect of chemical- and protein-mediated crosslinks between DNA segments on DNA knot formation. Finally, we consider DNA knot formation in vivo.