We didn't even have a piece of paper to start with. I'd been told that most films start with a small piece of paper. On it is written a one-line version of your film. "Imagine Vera Drake meets The Cider House Rules." "It's like Fantastic Four, but with Anthony Hopkins on a horse." "A small-town family murder their cleaner and then bury her in some waste ground that then gets built on by a shoe manufacturer, whose shoes are haunted by her deranged spirit, resulting in a little girl kicking the town's mayor to death but with very clean shoes: it's basically Fargo with a twist of Wizard of Oz." "Will Smith owns a zoo ..."

Instead, I went into meetings with financiers and distributors carrying nothing but a pitch in my head. "I want to make a comedy about what happens when the US president and the British PM are very keen on a course of military action in the Middle East that no one else thinks is a good idea. We watch everyone under them wonder what to do." That was it, basically.

Rancid whiskey galore

Six months later, I was completing the last day of filming of In the Loop. It was an unfeasibly hot afternoon in New York, and Tom Hollander, Peter Capaldi and Chris Addison were stuffed in the back of a car driving over a bridge into Manhattan and towards the United Nations building. This is where In the Loop climaxes, several hours before a security council debate to vote on war. The car scene involves Capaldi, playing Malcolm Tucker, the prime minister's director of communications, turning to Hollander as Simon Foster, the minister for international development, and saying to him: "If I could, I'd punch you into paralysis."

To have room enough for myself and the camera and sound team, we used a stretch limo to shoot the interior. It was clearly the sort of car that got hired out to F-list New York celebrities. Purple leather clad the walls, and a hideous bar of decanters packed one of the sides. Terrible, sordid things had been done in the back of this car by coke-addled superstars and cosmetically enhanced dancers. It was the seediest thing I've ever stepped into.

But there was an air of excitement, too: we were in the back of a stretch limo driving into Manhattan for our movie. We shot the scene; it was the end of the film for Peter, Tom and Chris, so to celebrate Tom reached over, grabbed some whisky glasses from the bar, filled them from one of the decanters, and we all said "Cheers" and drank. What we drank turned out to be hot, stale whisky mixed with the spit of over-the-hill sports stars and ambitious weathergirls and left to stand in the sun for five months. It was the most disgusting thing I've ever put in my mouth, and that includes anything I swallowed as a toddler. As this rancid swill tumbled down our throats we arrived at the End of The American Dream.

I consoled myself it was probably good that this happened. Part of In the Loop is about how stupidly weak-kneed we Brits get when we think of America, of how we lose our dignity and even our principles once we get the chance to soak up American culture. I'm thinking particularly of UK politicians going out to Washington, looking grand and statesmanlike as they leave Heathrow airport and suddenly turning into gurning kids if they get anywhere near the White House. Lack of dignity is what characterises us on these occasions, so it was good it hit us all in the throat that day.

Meeting the CIA

So, six months before this moment, I might not have had a piece of paper, but I went to my meetings able to pad them out with tales of many research trips I made to Washington. I'd established contact with a political blogger out in DC who fixed me up with US State Department staffers and Senate workers and Pentagon officials and even a CIA guy, who could brief me on the ins and outs of Washington life. At least two people told me that Condoleezza Rice was a bit rubbish. She got rather star-struck in Washington and never really stood up to Dick Cheney and Donald Rumsfeld. Both of the guys I met said: "And, as a result, people got killed." The CIA guy added: "And that's what really pisses me off!" and as he said it, for the first time in our meeting, he looked rather frightening. He had the look of a man who knows how to empty someone else's bowels out by simply touching a vein.

Actually, what intrigued me most was that he told me the CIA was mostly dull and disappointing. He said he spent a long time working there dreaming that one day someone would come and tap him on his shoulder and point over to a door at the far end of the room and say: "See that door? That's where the real CIA is. Go through there and you'll see a room full of massive screens and loads of bleeping computers. It's just like in Mission: Impossible." But, alas, that day never came.

It's the normality of life in American government that fascinated me; the fact that major international events can be affected simply because someone was late for work one day, or someone else forgot to cancel an order, is both frightening and profoundly understandable. We all make so many mistakes at work, and spend so much of our time trying to hide them, that I thought a good comedy could be made out of that sort of thing happening in high office. I've seen Washington portrayed in film either as sinister or noble; never scuzzy and a let-down.

I sought out examples of the latter. While in Washington, I met a 23-year-old who had a policy paper on Central America and, because everyone higher than him was too busy, was told just to get on with it and run the entire Central American budget. I met junior policy advisers for very senior senators, former presidential nominees some of them, who get rung up by their bosses and asked for urgent information on subjects that are being debated and about to be voted on in the Senate. The advisers all say: "Give me 20 minutes", which sounds impressive, but which is actually the time it takes to Wikipedia the subject, rejig it to make it look like it's their own, and email it to their senator's BlackBerry. Within an hour, this "advice" is being referred to in a major speech in the Senate and votes, some of them votes for war, are being cast.

Tales from the script

So I brought all these stories back with me to tell to people with money. This is the scary bit of film-making, I discovered. This is when you realise what your undertaking is: not some great artistic project designed to explore the limits of cinema but actually the borrowing of a sod of a lot of other people's cash so that you can do what you like. Sometimes in these meetings you're made aware of that fact. Someone can listen to your passionate delivery and then say, "Not sure"; or, "England's expensive. Can you film in Hungary and make it look like New York?"; or, "There's a great part in this film for my wife"; or, "I've got some jokes for you. They're probably a bit broader than you're used to, but hear me out"; or, most demoralising of the lot, "I've got a plane to catch." I've had film finance meetings in the past when these things have been said to me.

I was much luckier with In the Loop. BBC Films were on board from the start, with executive producers David Thompson and Christine Langan keen to take the model of my TV show The Thick of It and expand its scope and ambition. The British Film Council soon joined us. That was good. Because I knew they weren't going to have a script until much later on in the process.

That was the other problem: the fact I like to keep the script-writing back until we've cast the parts, and maybe even have the actors to hand, to workshop the ideas with the writers. Sounds great, until you try making a film on this premise. Some people won't give you money until you can tell them who's in it, and you can't get people in it until their agents have seen a script, but I didn't want to get a script together until we had a cast, and some actors won't commit until they know the film's got money. In the end, we resorted to downright duplicity of a complexity surpassed only by international banking organisations.

We sort of made up a script to show to actors early on, telling them all the time it would probably change. Call this Script 1: The One That Makes it Look Like We Know What We're Doing. Once we get our cast, we can then work with them properly, workshopping and rehearsing, all the time expanding and adding detail. As a result, this actual script, the real script, grows and grows. It turns massive.

I knew I would cut it down later but at this stage it was nearly three times as long as any decent film script has the right to be. So call this Script 2: The One That Looks Like We Actually Don't Know What We're Doing. A normal film script, I discover, is about 90 pages long. Ours was by now 240. Unfortunately, the existence of this script coincided with the moment all the money was being signed off, and insurance was being put in place: for which, of course, some very important people need to see a script. Rather than send them Script 2, we write another script that's an awful lot shorter, because about two out of every three words have been cut. It makes no sense, and is never going to be shot. Call this Script 3: The One That Looks Most Like We Know What We're Doing Except We're Never Going to Do it.

Anyway, we got the green light (though I forget on which script).

Basketball with Gandolfini

The only character I retained from the TV series The Thick of It was Peter Capaldi's Malcolm Tucker, a furious ball of obscenity, guile, threats and quite brilliant media manipulation that usually leads to the psychological destruction of those around him, hopefully with hilarious consequences. I recast the rest of the roles, drawing on some of the Thick of It regulars to play new parts, and bringing in new actors I've always admired and thought would be right for this new ensemble I was putting together.

Gina McKee plays an extremely tired and cynical press officer who couldn't give a toss what anyone does. Foster (Hollander), the minister, is permanently concerned yet dithers about what to do, which is the heart of the film. There's a scene in a car in which he ponders whether to resign or stay, and wonders whether resigning is easy, while doing nothing is much more difficult since it goes against every fibre of his being. This breaks out into an argument in which his aide, Toby, played by Chris Addison, argues quite forcefully that doing the wrong thing is much braver than doing the right one.

The scene is inspired by a passage in Clare Short's diaries in which, after pondering quite publicly whether she should resign from the cabinet in the build-up to the invasion of Iraq, she writes that she convinced herself that not to resign was actually the braver thing to do. It's a ghastly example of a pretty decent person tying herself in moral knots because she has fundamentally been made rubbish by the tempo of politics. That's the essence of the film I wanted to make: the sight of fundamentally OK people - not evil bastards but not gloriously brave, either - the sort of people you and I can identify with.

We start off with the UK government, and then we see a whole new cast of American politicos at the US State Department, and follow their own office politics. So I had to bring in a whole new team of actors I hadn't worked with before. James Gandolfini was someone I'd spoken to several times about an HBO project I'm working on, and he mentioned how much he enjoyed and "got" The Thick of It. When we wrote the part of a Pentagon general who sounds like he can talk the talk but never really manages to walk the walk, I instantly thought of him, simply because it was casting a little bit against type. I liked the idea of him being authoritative but pointless. And, it turned out in rehearsal and the shoot, James is very, very good at slapstick. He's a natural comic performer, with a deep love of WC Fields. For many on set, though, he was their hero from The Sopranos and I'll never forget the look on people's faces when James turned up in the middle of the wet north London car park where we were all stationed, with a basketball, asking if anyone wanted to shoot some hoops with him. Suddenly, even the most unsporty nerd within a mile had developed a passion for the art of basketball and queued up to play. It was great to see excitement detonate so instantly over that wide a radius.

Steve Coogan's fine wines

Filming started, and the great unstoppable machine commences. A shoot is relentless, so many questions that need answering, so many problems requiring solutions, even though my default take on any problem is: "Can't it wait till tomorrow?" Directing a film is, however, the one thing I've always wanted to do and get right since I was about 18, so all of this was in no way anything but the most fun I've ever had with other people's money. It's knackering, though, so I asked for a quiet space where at lunchtime I could go away and think and maybe de-stress.

The room I got was right next to the main production offices. Bad mistake. As I shut my eyes each lunchtime, I could hear shouted around the place the many impending crises the producers Kevin Loader and Adam Tandy had done their deftest to keep from troubling me. "Carol, we've just heard none of us are insured. We've got to stop the film." "Jon, we haven't got permission to say the words 'United Nations' or 'America'." "Brian, any news on that set that's on fire?" "What d'you mean, he's dead? He can't be dead: I saw him this morning!"

It was actually less stressful being back on the set.

Sometimes, as we were shooting, new thoughts and story ideas emerged. We suddenly had the need to meet a member of the public who causes the minister a lot of ball-ache. The wall of the minister's constituency office in Northampton is leaning over into this guy's mother's back garden, and is on the verge of collapsing. It's a small scene, but had big impact. I needed someone who could do a comic tour de force in an instant, which is why I called Steve Coogan. Steve and I hadn't really worked together since the last series of I'm Alan Partridge six years ago, and we'd often talked since about doing a film.

Now Steve, who's in the middle of filming something else, spots a Friday he's got off, and comes to shoot with us. Within seconds, I realise how much I'd forgotten how spontaneously hilarious he is. It's like we were only working yesterday. The words and actions and improvised asides flood out. His character berates the minister for "flying all over the world drinking ... what is it? What d'you call that wine?" There's a pause. "I don't know," says Tom Hollander, who then improvises a scene with a clothes peg bag that he mistakes for a little girl's dress. The scene goes on for half an hour, then, as the minister leaves to get in his car, Steve shouts across his mother's back garden at the top of his voice: "Chateaux Neff du Pap! I knew I'd remember."

You probably had to be there. It was hilarious to watch. The scene has been cut from the final edit. The edit is the grim piece of ruthlessness that hangs over any shoot. I had four months to cut my film into shape. The first edit had it at four and a half hours long. With depressing regularity, I pulled out favourite scenes and moments and looks, to arrive at the funniest 90 minutes I could make it. I'm happy with the result, but wouldn't want to do it again: it's like colonic irrigation in that respect.

Popular with old ladies

And so, a year from the meetings that had no piece of paper in them, we take In the Loop to Sundance, and it goes down well. Suddenly, everyone is excited: the process is over, but a new one seems to be starting up. I have my film, but I need my moment as a film-maker. This comes on a cold night in February, as In the Loop opens the Glasgow film festival. Glasgow is my home town. My mum, in her 80s, and her sisters all come. They sit in the front row, and watch a giant, 40-foot-high Malcolm Tucker swear at them. Peter Capaldi's brought his mum as well, and she sits at the front, too.

Next day, he sends me a photo. It's of my film premiere. It's of a row of little old ladies sitting in a dark cinema. It's probably not the most glamorous photo in the history of movies, but it makes the whole process seem rather special.

Certainly much more special than a gob full of rancid whisky.

• In the Loop opens on 17 April