Barium (Ba2+) is a classic permeant blocker of potassium (K+) channels. The “external lock-in effect” in barium block experiments, whereby the binding of external K+ impedes the forward translocation of the blocker, provides a powerful avenue to investigate the selectivity of the binding sites along the pore of potassium channels. Barium block experiments show that the external lock-in site is highly selective for K+ over Na+. Wild-type KcsA was crystallized in low K+ conditions, and the crystals were soaked in solutions containing various concentrations of barium. Structural analysis reveals open and closed gate conformations of the KcsA channel. Anomalous diffraction experiments show that Ba2+ primarily binds to the innermost site S4 of the selectivity filter of the open-gate conformation and also the site S2, but no binding is detected with the closed-gate conformation. Alchemical free-energy perturbation calculations indicate that the presence of a Ba2+ ion in the selectivity filter boosts the specificity of K+ binding relative to Na+ in the external sites S0–S2.