Pre-production
While collaborating on Hidamari Sketch and Bakemonogatari, Akiyuki Shinbo told Aniplex producer Atsuhiro Iwakami he wanted to create a new magical girl series, beginning the development of Puella Magi Madoka Magica. According to Shinbo, while talking with Iwakami, he had mentioned that there was still improvements for him to make to the genre from one of his previous series. During the early planning stage, Iwakami decided not to adapt an existing work to give Shinbo more freedom in his directional style. Another goal of the project was to develop an anime that would appeal to a wider audience than the usual demographic for media within the magical girl subgenre. Iwakami and Shinbo intended their series to be accessible to "the general anime fan". Gen Urobuchi was suggested to be the writer by Iwakami due to his work with the Fate/Zero light novel (which Iwakami gave Shinbo a copy of the first volume to), and Shinbo asked Ume Aoki to be character designer. The series was Urobuchi's first time writing the screenplay for an anime on his own. Takahiro Kishida was arranged to adapt Aoki's character designs for the television series. The series' working title was, at that point, Magical Girl Apocalypse Madoka Magica (魔法少女黙示録 まどかマギカ), and the staff got used to calling it Madoka Magica during production. It was proposed that the "Magical Girl Apocalypse" part of the title be dropped and the series instead be titled simply "Madoka Magica", but Shinbo was adamant in retaining the "Magical Girl" segment of the title, which stuck.
In his role as producer, Iwakami took a mostly hands-off approach to the series. Because Puella Magi Madoka Magica is an original series rather than an adaptation of an existing work, his main goal was "coming up with a high-quality piece of entertainment". After helping to recruit the staff, he allowed them freedom to develop the content of the story, providing minimal guidance. After viewing the character designs that Aoki created, he was sure he could trust the creative talent of the team. In an interview with Anime News Network after the series finished airing in Japan, Iwakami said, "I don't matter much; it's up to those talents to do their work. If something comes to a stand-still I might intervene, but they did an excellent job and I was very happy seeing the results in episode one."
During the planning phase, Iwakami asked Urobuchi to make the storyline "heavy". Shinbo specified it should contain copious amounts of blood and violence, elements that were rare in the magical girl genre. Iwakami also asked for many of the magical girl characters to be killed throughout the series. Initially, Urobuchi was unsure of how to approach the work due to his lack of experience with the "magical girl" genre, as well as the fact that he was under the impression that the team consisting of Shinbo, Shaft, and Aoki was that of the "cuter" Hidamari Sketch franchise despite the fact that he had heard he was recommended through Fate/Zero. He said that he had no trouble with these requirements, referencing his past reputation as a writer of very dark and somber stories, the extent of which Shinbo had not known; but found difficulty in mixing the dark elements with Aoki's particular character designs and the genre itself, adding that it seemed like he was "bullying" the Hidamari Sketch characters. To help with the writing, Urobuchi read Hidamari Sketch and noted its themes of "friendship" and then watched two of Shinbo's previous anime series: Magical Girl Lyrical Nanoha, which was a magical girl series, as well as Le Portrait de Petit Cossette, a gothic horror series. He decided to mix the cute characters of Hidamari Sketch with the "disturbing" and "mysterious" atmosphere of Le Portrait de Petit Cossette together in writing the series. Eventually, when the production design duo Gekidan Inu Curry, who had been working on a variety of Shaft works at the time, were added to the roster, Urobuchi said he believed that he could successfully link the two ideas together.
One objective was for the script to contrast starkly with the way the anime was to be marketed. Shinbo planned to advertise the series innocently and purely so as to deliberately conceal its dark undertones. For example, the title logo was rendered using rounded fonts that would appear harmless to audiences. Urobuchi further misled fans by using his Twitter account to persuade them the plot of the series was innocuous. The true nature of the series was disguised because Shinbo wanted its dark themes to be a complete surprise to the viewers. Inconsistencies in the script that neither Shinbo nor Urobuchi noticed would also later be caught by series director Yukihiro Miyamoto and film editor Rie Matsuubara.
Shinbo granted Urobuchi a large amount of autonomy in writing the series and determining the path of the story. In describing his interactions with Iwakami and Shinbo while working on the series, Urobuchi commented that "neither one is the type to show their hand, they would always wait for me to make the next move". To create a successful deconstruction of the magical girl genre, Urobuchi studied aspects of traditional magical girl media that were "troubling or overlooked". He also stated the plot development was heavily influenced by the character drawings by Aoki, and specifically credited horror fiction author Stephen King and Shinbo's previous aforementioned projects. Later speaking on the series' success as the culmination of his works with the studio, Shinbo specifically mentioned fellow Shaft director Shin Oonuma's Ef series as a work which helped him understand cute and beautifully drawn characters mixing with a story featuring heavy themes.
Urobuchi attributed his experience working on projects with screenwriters Ichiro Itano and Yōsuke Kuroda as a major influence in his writing for Puella Magi Madoka Magica, and has referred to both of them as his mentors. To set the initial pacing of the series, Urobuchi used a technique he credited to Kuroda; the first episode would throw the viewer into a later part of the story without any context. The second episode would define the rules governing the story's setting. The third episode would divulge a vital revelation in the plot to hook the viewer. The twist in the third episode was determined during the project proposal stage and involves the death of Mami Tomoe, the main character's mentor. This decision was controversial; Urobuchi said production staff continually approached him and asked him to reconsider because of their fondness for the character. He refused and the plot remained unchanged during production. Urobuchi realized this progression could be very hard for viewers to accept and might hurt the overall series' success with some audiences; he said, "I always thought this is an age where entertainment basically is about soothing and healing, like adopting a style where unchanging day-to-day life is to continue forever".
In an interview with Ultra Jump Egg, Urobuchi gave insight into his writing philosophy, stating that he believed the overarching plot of a story was more important than its characters. He said he would first determine the actions and the ultimate fate of a character before even assigning them a name, and contrasted this with other writing methods that first focused on developing the characters and then creating a storyline for them to follow. He again defended his decision to have Mami die, saying this could have the effect of making the character more memorable, saying, "I think there are quite many characters who became immortal exactly because they died, like Caesar Zeppeli in JoJo's Bizarre Adventure or Raoh in Fist of the North Star. Precisely because of the way they died, they were able to live forever."
Production designers Gekidan Inu Curry were also given an amount of freedom in rewriting certain parts of the script and storyboards. Although initially credited as production designers (later changed to "alternate space designers"), they had freedom to insert new details and to modify existing ones from the original script, such as during a scene in the final episode in which the team added black wings to Homura—something that was not included in Urobuchi's script. The themetic quotations and motifs from Faust and Through The Looking-Glass were also Gekidan Inu Curry's own ideas, according to Urobuchi. Urobuchi praised this aspect of the production, commenting, "additions by the animation production team added more mystery and depth to [the] characters, and without them, it would have been very difficult to write any further stories in the world of the series."
Urobuchi stated that Sayaka was his favorite character overall and that her storyline was the most enjoyable to write. Shinbo believed that Sayaka's grim fate by the end of the series was a slightly unfair destiny, and asked Urobuchi if it was possible to change the plot so Sayaka could be spared. Urobuchi declined, saying her death was integral to the overarching story. Shinbo then asked if she could be brought back to life, saying he had become very attached to the character. Urobuchi again refused, saying this would be impossible because of the already-established rules governing the story. Shinbo acquiesced to this, but said he believed there may have been too large a burden placed on the characters who were young, middle-school girls.
The alien character Kyubey was also envisioned and designed by Urobuchi. Iwakami stated that as one of the primary antagonists in the series, "the mash-up of cuteness and darkness is the central theme to Madoka, and Kyubey is an epitome of that theme". A central goal in Urobuchi's writing was to highlight the moral and ethical dissonance between Kyubey and the young middle school girls, which was done through actions such as Kyubey eating their own corpse to regain energy. He compared the character to monsters in the works of horror fiction author H. P. Lovecraft, commenting of Kyubey: "he (sic) isn't evil, it is his lack of feelings that make him scary". Urobuchi also remarked upon the moral ambiguity the series displays in an interview with Asahi Shimbun, stating "Al-Qaeda brought down the Twin Towers due to their self-righteousness. Justice for some people is an evil for others. Good intentions, kindness, and hope will not necessarily make people happy."
Due to unforeseen scheduling problems at Shaft, production of the series was postponed for three years following the completion of its writing. Once the issues were resolved, production continued without further complications. The animation studio led the conception and design of the witches, and created each one's individual backstory. Urobuchi had originally envisioned the witches to be similar to conventional monsters such as Godzilla, but upon seeing the surreal concept art for one of the main witches, Walpurgisnacht, he said; "How can Homura possibly fight against something like this?"
Gekidan Inu Curry's art style and design work is largely Czech- and Russian-inspired stop-motion animation. In their initial meeting with Shinbo for the series, the director told them that the series would be unlike Magical Girl Lyrical Nanoha and instead wanted them to think about the series as more of an extension of Le Portrait de Petit Cossette.
Although they were uncredited for the design work itself, animators Nozomu Abe and Tomohiro Kamitani were recruited as the series' weapon designers and supervised the drawings for all of the sequences they'd appear in as the series' action directors. Abe was responsible for the magical girl weapons, while Kamitani was responsible for all of the real-world weapons like firearms.
Iwakami and Shinbo recruited Yuki Kajiura to compose the soundtrack for the series after Urobuchi recommended her. Shinbo had previously worked with Kajiura on Le Portrait de Petit Cossette; Urobuchi told of the inspirational effect the music from that series had on him while writing parts of the script. He also said that he had long been a fan of Kajiura's anime soundtracks and praised her work ethic, saying she would always familiarize herself with the story while composing for a series. Japanese pop music duo ClariS was also commissioned to perform the series' opening theme "Connect" (コネクト, Konekuto). Iwakami involved himself in the song's development to ensure it would fit with the series, marking one of the few times he was involved in an aspect of the production. Both "Connect" and the ending theme "Magia" by Kalafina were revealed in a television commercial several weeks before the series' premiere in Japan.