The Spice Girl says she turned to the drug as her second marriage to film producer Stephen Belafonte broke down.
The 43-year-old insists she never took the Class A drug during the actual shows, but told The Sun she snorted two lines as soon as she woke up before praying to God for help.
“I was a sad, pathetic person. I was out of control,” she told the newspaper.
“It numbed my pain. It lifted me up enough to be ready to fire on all cylinders and forget about everything but the show.”
Mel further details her drug use in her new autobiography, ‘Brutally Honest’, as a way to cope with living with Belafonte, which she describes as “neurotic claustrophobia”.
She writes: “I was so low that two weeks into filming The X Factor I’d started using cocaine to get me through the run of the show.
“On so many levels I felt myself sinking. I had a routine. I was ashamed of what I was doing, but I felt I had to have it. I told myself God would understand and forgive me because he could see through all the glitter and the crap.
“He could see me. The mess. And cocaine could help that mess. Just for now. It numbed my pain.”
Mel adds that she never took the drug while she filmed the ITV show alongside Simon Cowell, Louis Walsh and Cheryl.
She says: “Once I was at work I didn’t need anything and I didn’t take anything.
“I’d crack jokes with Simon and the other judges and have a laugh with the crew.
“But as soon as I left the building, it was like in Cinderella, where everything turns back to shit and rats and pumpkins. The black emotions I was holding off crashed right down on top of me like fat, heavy bricks.
“The cocaine would come back out of my bag and up into my nose. One line, another line, and yes, another and another. My quick-fix answer was cocaine.”
Mel, AKA Scary Spice, was married to Belafonte for ten years, but they filed for divorce last year.
She says: ”I felt emotionally battered, estranged from my family. I felt detested by the very man who promised to love and protect me.”
Earlier this year a judge in Los Angeles ruled that Mel would have to pay her ex-husband’s legal fees of $350,000 (£270,000), as well as £3800 a month to him in child support.
In August, Mel revealed she had been diagnosed with post-traumatic stress disorder, and was set to check into a therapy programme after reliving her past for her autobiography, which is being serialised in The Sun.
‘BRUTALLY Honest’ by Melanie Brown with Louise Gannon (Quadrille, £17.99) is published on 27 November.