A general theoretical and experimental framework for nanoscale electromagnetism