Understanding the relationships between neural activity and behavior represents a critical challenge, one that requires generalizable statistical tools that can capture complex structures within large datasets. We developed Time-REsolved BehavioraL Embedding (TREBLE), a flexible method for analyzing behavioral data from freely moving animals. Using data from synthetic trajectories, fruit flies, and mice we show how TREBLE can capture both continuous and discrete behavioral dynamics, can uncover behavioral variation across individuals, and can detect the effects of optogenetic perturbation in an unbiased fashion. By applying TREBLE to the freely moving mouse, and medial entorhinal cortex (MEC) recordings, we show that nearly all MEC neurons encode information relevant to specific movement patterns, expanding our understanding of how navigation is related to the execution of locomotion. Thus, TREBLE provides a flexible framework for describing the structure of complex behaviors and their relationships to neural activity.