Castellar del Riu is a municipality in the comarca of Berguedà, in the Catalonia region of northern Spain. It lies within the province of Barcelona, in the foothills of the Pyrenees.
Unusually for a Catalan municipality, its administrative centre is not a village. The municipal government is located at Llinars, which consists of just a few municipal buildings, including a small sports centre, rather than a settled village nucleus.
The municipality is one of several small, sparsely populated administrative units that make up the Berguedà comarca, a largely rural area of Catalonia.