MIT conducted tests on the caffeine effects in coffee and found that only one cup of coffee in the morning and another in the afternoon is required to give a the brain a buzz and maintain a mild caffeine high. Caffeine is relatively high in coffee at 135 mg for an 8 oz. cup
In another study by a different organization they found that it may take 10 to 14 hours to eliminate all traces of caffeine from the body. The stimulating effects may continue as long as caffeine stays in the body. This the reason why it may not have a restful sleep if you have coffee in the evening or very late in the afternoon.
My personal cutoff time for coffee is 3 pm. After that time if I drink coffee, or anything with caffeine, I can expect to either have a tough time falling asleep or wake up during the middle of the night a stare at the ceiling.