Steven Moffat has cannibalised his life and turned it into art. He describes his first sitcom, Joking Apart, as a cathartic dissection of his own divorce. His second, Chalk, which begins next Thursday on BBC1, is a reworking of his time as a teacher or "My Life as a Prof".

In this, he is merely following in the footsteps of many famous former teachers - Alan Bleasdale, Jimmy McGovern and Roddy Doyle all spring to mind - who have converted lecturing into literature. Moffat, a personable Scot in a grey chunky-knit sweater, is not surprised about the plethora of autobiographical teacher tales. "There are a vast number of writers who were teachers," he observes. "It is the only job they had in the real world before becoming cappuccino-sipping socialist writers. I've written about my divorce and about teaching. All that's left is my early TV writing career.

"In a profession like TV, which is largely staffed by people who used to teach," he continues, "it is amazing that there aren't more teacher programmes. In format meetings, they are always listing possible jobs to make series out of. These must have big rooms which lots of diverse people come in and out of - and that's a staff-room."

Teaching also attracts larger-than-life characters - ready-made sitcom fodder. In an echo of Basil Fawlty, the manic deputy head of Galfast High (David Bamber, aka Mr Collins from Pride and Prejudice) spends the first episode of Chalk ever more frantically trying to hide from pupils the corpse of a teacher who has sat through his last two classes without anybody realising he's dead.

"Chalk is your worst nightmare of what you assumed teachers were doing in the staff-room when you were at school," Moffat laughs. "Staffrooms are funny places, full of articulate, mad people. They have a tremendous sense of black humour, but there's a layer of dust over them. They are immature because they're in a children's environment all the time. They have a strange perspective; because they spend all day with kids, they are more aware of kids' culture than adults'. When they read about a former pupil who has become head of ICI, they always say, 'But that boy's an idiot. He's crap at geography.' The boy is condemned forever because in the 1960s he didn't know all the capitals of the Third World."

Despite their scandalously low status - matched only by their scandalously low pay - teachers are still held in affection, according to Moffat. "A lot of them could have done anything they wanted," he contends. "You meet some very learned people in teaching. I had one teacher who knew absolutely everything - from 17th-century poisons to the early works of Ian Fleming."

Having written 43 episodes of the award-winning children's school drama, Press Gang, and with a father and sister in the profession, Moffat is still dusted with chalk. Although passionate about education ("the government talk about the specially talented needing more education, but that's absurd, the equivalent of hospitals for the healthy."), he stresses that Chalk is a sitcom, not some banner-waving, agitprop pamphlet.

He trusts that his family will still talk to him and that his former colleagues will see the joke. "Teachers will find it funny," he declares, "because it has certain notes of accuracy. They'll recognise familiar myths like dead teachers in front of a class and the attitude of contempt for the idea of having to teach - which is something they put on. They say outrageous things about kids in the staffroom, but they don't mean them."

Getting into his stride, he carries on: "they'll also recognise the pathological preference for science over arts and all that league-table shit. An official teaching organisation couldn't say, 'It's a very faithful portrayal,' but I hope they'd say, 'It's a comedy series. Why take it seriously?' You couldn't claim it is the most flattering series, but, there again, people continued to stay at hotels after Fawlty Towers."

Chalk is on BBC1 at 9.30pm next Thursday