The idea for Pan's Labyrinth came from Guillermo del Toro's notebooks, which he says are filled with "doodles, ideas, drawings and plot bits". He had been keeping these notebooks for twenty years. At one point during production, he left the notebook in a taxi in London and was distraught, but the cabbie returned it to him two days later. Though he originally wrote a story about a pregnant woman who falls in love with a faun, Sergi López said that del Toro described the final version of the plot a year and a half before filming. Lopez said that "for two hours and a half he explained to me all the movie, but with all the details, it was incredible, and when he finished I said, 'You have a script?' He said, 'No, nothing is written'". López agreed to act in the movie and received the script one year later; he said that "it was exactly the same, it was incredible. In his little head he had all the history with a lot of little detail, a lot of characters, like now when you look at the movie, it was exactly what he had in his head".
Del Toro got the idea of the faun from childhood experiences with "lucid dreaming". He stated on The Charlie Rose Show that every midnight, he would wake up, and a faun would gradually step out from behind the grandfather's clock. Originally, the faun was supposed to be a classic half-man, half-goat faun fraught with beauty. But in the end, the faun was altered into a goat-faced creature almost completely made out of earth, moss, vines, and tree bark. He became a mysterious, semi-suspicious relic who gave both the impression of trustworthiness and many signs that warn someone to never confide in him at all.
Del Toro has said the film has strong connections in theme to The Devil's Backbone and should be seen as an informal sequel dealing with some of the issues raised there. Fernando Tielve and Íñigo Garcés, who played the protagonists of The Devil's Backbone, make cameo appearances as unnamed guerrilla soldiers in Pan's Labyrinth. Some of the other works he drew on for inspiration include Lewis Carroll's Alice books, Jorge Luis Borges' Ficciones, Arthur Machen's The Great God Pan and The White People, Lord Dunsany's The Blessing of Pan, Algernon Blackwood's Pan's Garden and Francisco Goya's works. In 2004, del Toro said: "Pan is an original story. Some of my favourite writers (Borges, Blackwood, Machen, Dunsany) have explored the figure of the god Pan and the symbol of the labyrinth. These are things that I find very compelling and I am trying to mix them and play with them." It was also influenced by the illustrations of Arthur Rackham.
Del Toro wanted to include a fairy tale about a dragon for Ofelia to narrate to her unborn brother. The tale involved the dragon, named Varanium Silex, who guarded a mountain surrounded by thorns, but at its peak is a blue rose that can grant immortality. The dragon and the thorns ward off many men though, who decide it is better to avoid pain than to be given immortality. Although the scene was thematically important, it was cut short for budget reasons.
There are differing ideas about the film's religious influences. Del Toro himself has said that he considers Pan's Labyrinth "a truly profane film, a layman's riff on Catholic dogma", but that his friend Alejandro González Iñárritu described it as "a truly Catholic film". Del Toro's explanation is "once a Catholic, always a Catholic," however he also admits that the Pale Man's preference for children rather than the feast in front of him is intended as a criticism of the Catholic Church. Additionally, the priest's words during the torture scene were taken as a direct quote from a priest who offered communion to political prisoners during the Spanish Civil War: "Remember my sons, you should confess what you know because God doesn't care what happens to your bodies; He already saved your souls."
In regards to whether or not the fantasy underworld was real or a product of Ofelia's imagination, del Toro stated in an interview that, while he believes it is real, the movie "should tell something different to everyone. It should be a matter of personal discussion". He then mentioned there were several clues in the movie indicating the underworld was indeed real.
The film was shot in a Scots Pine forest situated in the Guadarrama mountain range, Central Spain. Guillermo Navarro, the director of photography, said that "after doing work in Hollywood on other movies and with other directors, working in our original language in different scenery brings me back to the original reasons I wanted to make movies, which is basically to tell stories with complete freedom and to let the visuals really contribute to the telling of the story".
The pale man's eyes on his hands is a feature shared by the Japanese mythological monster the Tenome (a name which means "hand eyes").
Pan's Labyrinth employs some computer-generated imagery in its effects, but mostly uses complex make-up and animatronics. The giant toad was inspired by The Maze. Del Toro himself performed the noises. The mandrake root is a combination of animatronics and CGI. Del Toro wanted the fairies "to look like little monkeys, like dirty fairies", but the animation company had the idea to give them wings made of leaves.
Jones spent an average of five hours sitting in the makeup chair as his team of David Martí, Montse Ribé and Xavi Bastida applied the makeup for the Faun, which was mostly latex foam. The last piece to be applied was the pair of horns, which weighed ten pounds and were extremely tiring to wear. The legs were a unique design, with Jones standing on 20-cm-high lifts (8 in), and the legs of the Faun attached to his own. His lower leg was eventually digitally erased in post production. The Faun's flapping ears and blinking eyes were remotely operated by David Martí and Xavi Bastida from DDT Efectos Especiales while on set. Del Toro told Jones to "go rock star ... like a glam rocker. But less David Bowie, more Mick Jagger".
The Captain's room, as shown in the scene where Captain Vidal is shaving, is supposed to resemble his father's watch, which del Toro says represents his troubled mind.
A bout of weight loss on Del Toro's part inspired the physical appearance of the saggy-skinned Pale Man. In order to see while performing the part, Doug Jones had to look out of the character's nostrils, and its legs were attached to Jones over the green leotard which he wore.
The film uses subtitles for its translation into other languages, including English. Del Toro wrote them himself, because he was disappointed with the subtitles of his previous Spanish film, The Devil's Backbone. In an interview, he said that they were "for the thinking impaired" and "incredibly bad". He spent a month working with two other people, and said that he did not want it to "feel like... watching a subtitled film".