Drug dealer Eiraj Ali flushed his stash of cocaine down the loo as the police raided his family's home in Watford.
But he left a trail of white powder from his bedroom to the bathroom which a sniffer dog picked up and indicated it was drugs.
Prosecutor Andrea Scott-Lynch told St Albans crown on Wednesday: "The police raided the family home on Wednesday, December 18, last year. Mr Ali was seen coming out of the toilet. There was white powder on the floor from the bathroom to his bedroom.
"The officers came to the conclusion that Mr Ali had been trying to flush substances away. A police dog indicated that the powder on the floor was drugs."
When they searched the bedroom, more cocaine was found on the floor, on a TV unit and in boxes. Scales, dealer bags and £1,700 cash was seized. In all, 14.02 grams of cocaine, with a street value of between £560 and £840, was recovered.
Ali, 26, of Brett Place in The Harebreaks, pleaded guilty to possessing a Class A drug with intent to supply. In 2006 he was sentenced for possessing cocaine and heroin with intent to supply.
Dan Hart, defending, said unemployed Ali had pleaded guilty at the first hearing. "He has found it difficult to resist drugs and has been addicted at times. He ran up £800 debts to a drug dealer and, to pay it off, agreed to take part in the supply of drugs."
He said his previous offence of supplying drugs in north Watford was eight years ago.
Mr Hart said Ali accepted he was facing a jail sentence. He went on: "He will use his time in custody to obtain qualifications to put himself in a stronger position to obtain employment on his release."
Recorder David Mayall jailed him for 40 months and ordered that the cocaine, scales and bags be destroyed.
He told him: "When the police entered, you were observed exiting the upstairs toilet. You had tried to get rid of as much of your drugs as possible.
"It was a significant operation you were running from your bedroom."
A confiscation hearing to deal with the £1,700 and any other money Ali is thought to have obtained from drug dealing is to be fixed at a later date.