Sensing the environment and reacting to it is essential for survival and procreation of most organisms. Caenorhabditis elegans senses soluble chemicals with transmembrane proteins (TPs) in the cilia of its chemosensory neurons. Development, maintenance and function of these cilia rely on intraflagellar transport (IFT), in which motor proteins transport cargo, including sensory TPs, back and forth along the ciliary axoneme. Here, we use fluorescence imaging of living worms and perform single-molecule tracking experiments to elucidate the dynamics underlying the ciliary distribution of the sensory TP OCR-2. Our quantitative analysis of the single-molecule trajectories reveals that the ciliary distribution of OCR-2 depends on an intricate interplay between IFT-driven transport, normal diffusion and subdiffusion that depends on the specific location in the cilium. These insights in the role of IFT and diffusion in ciliary dynamics contribute to a deeper understanding of ciliary signal transduction and chemosensing.