A cup of coffee three hours before bedtime may keep you awake, scientists say, BBC reports.

The study published in Science Translation Medicine, says that caffeine delays the production of melatonin, the hormone that induces sleep, and slows down the body's internal clock.

The study showed that intake of coffee three hours before bedtime delayed the production melatonin by about 40 minutes, making it harder to sleep.

Dr John O'Neill, one of the researchers from the Medical Research Council's Laboratory of Molecular Biology in Cambridge, told the BBC News website,

"If you're tired and having a coffee at night to stay awake, then that is a bad idea, you'll find it harder to go to sleep and get enough sleep."

As part of the study, cells grown in a dish were exposed to caffeine and it was seen that the drug was able to change the chemical clocks in every cell of the human body.

In another experiment, five people at the University of Colorado Boulder were isolated in a sleep laboratory for 50 days and kept in a very dim light. The experiment showed that intake of coffee in the evening slowed the body clock by 40 minutes.

However, Dr O'Neill said it would be a speculation to set a cut off time for drinking coffee in the evening.

The study could prove helpful to people with sleep disorders and people who naturally woke up too early.

"It could be useful with jet lag if you are flying east to west where taking caffeine at the right time of day might speed up the time it takes to overcome jet lag," he added.

Prof Derk-Jan Dijk, from the University of Surrey, told the BBC: "Individuals differ in their sensitivity to caffeine, and if coffee drinkers experience problems with falling asleep, they may try to avoid drinking coffee in the afternoon and evening."

Tags Coffee