The story is inspired by the Maoist insurgency in Peru known as the Shining Path. Its leader Abimael Guzmán, who was known by the nom de guerre President Gonzalo, was captured in an apartment above a ballet studio in the capital city of Lima in 1992. The ballet teacher Yolanda was based on Maritza Garrido Lecca, the woman in whose apartment Guzmán was found. Bardem's character was inspired by Benedicto Jimenez and Gen. Antonio Ketin Vidal, the leading figures responsible for Guzmán's capture.
In the beginning of the film, one of the revolutionaries tells a checkpoint security guard that his dead dog's name is Tupac. Tupac Amaru was the last indigenous leader of the Inca people in Peru and Tupac Amaru II was the leader of the 1780s uprising in Cuzco, Peru (the late hip-hop artist Tupac Shakur is named after the latter).
The depiction of the dogs hanging was based on an actual occurrence where several dogs were found hanging from street lights in central Lima one December morning with profane messages denouncing Chinese leader Deng Xiaoping (who Shining Path leader Abimael Guzman thought had betrayed the communist revolution). The dynamite inserted into the dogs' bodies was based on rumors that the hanging dogs may have contained explosives, though no explosives were actually found on the dogs when they were cut down.