Many species orient towards Earth's magnetic field, but how the nervous system detects magnetism is not known. Here, the authors show that Caenorhabditis elegans also orients to Earth's magnetic field, during vertical burrowing, and that the AFD pair of sensory neurons show calcium responses when the worms are exposed to an Earth-strength magnetic field. This calcium response even occurs in mutant strains that have impaired synaptic transmission, suggesting that AFD neurons could be directly magnetosensitive. Thus, C. elegans may be a useful model for further study of neural detection of magnetic fields.