A substantial decrease in the number of synapses occurs in the mammalian brain from the late postnatal period until the end of life. Although experience plays an important role in modifying synaptic connectivity, its effect on this nearly lifelong synapse loss remains unknown. Here we used transcranial two-photon microscopy to visualize postsynaptic dendritic spines in layer I of the barrel cortex in transgenic mice expressing yellow fluorescent protein. We show that in young adolescent mice, long-term sensory deprivation through whisker trimming prevents net spine loss by preferentially reducing the rate of ongoing spine elimination, not by increasing the rate of spine formation. This effect of deprivation diminishes as animals mature but still persists in adulthood. Restoring sensory experience after adolescent deprivation accelerates spine elimination. Similar to sensory manipulation, the rate of spine elimination decreases after chronic blockade of NMDA (N-methyl-D-aspartate) receptors with the antagonist MK801, and accelerates after drug withdrawal. These studies of spine dynamics in the primary somatosensory cortex suggest that experience plays an important role in the net loss of synapses over most of an animal's lifespan, particularly during adolescence.