We present a lattice calculation of the electromagnetic (EM) effects on the masses of light pseudoscalar mesons. The simulations employ 2+1 dynamical flavors of asqtad QCD quarks, and quenched photons. Lattice spacings vary from
≈0.12 fm to
≈0.045 fm. We compute the quantity
ϵ, which parameterizes the corrections to Dashen's theorem for the
K+-
K0 EM mass splitting, as well as
ϵK0, which parameterizes the EM contribution to the mass of the
K0 itself. An extension of the nonperturbative EM renormalization scheme introduced by the BMW group is used in separating EM effects from isospin-violating quark mass effects. We correct for leading finite-volume effects in our realization of lattice electrodynamics in chiral perturbation theory, and remaining finite-volume errors are relatively small. While electroquenched effects are under control for
ϵ, they are estimated only qualitatively for
ϵK0, and constitute one of the largest sources of uncertainty for that quantity. We find
ϵ=0.78(1)stat(−11+18)syst and
ϵK0=0.035(3)stat(20)syst. We then use these results on 2+1+1 flavor pure QCD HISQ ensembles and find
mu/md=0.4529(48)stat(−167+150)syst.