Extracellular potassium concentration affects the membrane potential of neurons, and, thus, neuronal activity. Indeed, alterations of potassium levels can be related to neurological disorders, such as epilepsy and Alzheimer's disease, and, therefore, selectively detecting extracellular potassium would allow the monitoring of disease. However, currently available optical reporters are not capable of detecting small changes in potassium, in particular, in freely moving animals. Furthermore, they are susceptible to interference from sodium ions. Here, we report a highly sensitive and specific potassium nanosensor that can monitor potassium changes in the brain of freely moving mice undergoing epileptic seizures. An optical potassium indicator is embedded in mesoporous silica nanoparticles, which are shielded by an ultrathin layer of a potassium-permeable membrane, which prevents diffusion of other cations and allows the specific capturing of potassium ions. The shielded nanosensor enables the spatial mapping of potassium ion release in the hippocampus of freely moving mice.