Two doctors at Penn State University have developed Caffeine Zone, a free iOS app that tells you the perfect time to take a coffee break to maintain an optimal amount of caffeine in your blood — and, perhaps more importantly, it also tells you when to stop drinking tea and coffee, so that caffeine doesn’t interrupt your sleep.

You’ve probably heard of being “in the zone” — a period where your brain is firing on all cylinders and no obstacle seems insurmountable — but did you know that there’s an optimal “caffeine zone” too? To find the boundaries of this zone, the authors of the app, doctors Frank E. Ritter and Kuo-Chuan Yeh, pored through peer-reviewed studies. They found that between 200 and 400 milligrams (mg) of caffeine in your bloodstream provides optimal mental alertness, and that below 100mg of caffeine is ideal for sleeping.

The rate at which caffeine is absorbed, metabolized, and broken down by your body (pharmacokinetics) is very well understood, though it varies from person to person, depending on your size, liver function, age, and so on. It takes about an hour for caffeine to reach its full effect, and has a half-life of around five hours in a normal adult — meaning if you consume a large filter coffee, which contains around 240mg of caffeine, you will have 120mg in your blood stream after five or six hours.

The Caffeine Zone app shows you a pretty graph of this in action (pictured above). You hit the Consume Caffeine button, pick your poison (tea/coffee/gum/other), and the app plots a graph of your caffeine level. A green bar represents the “caffeine zone” that you’re trying to hit, and a blue bar shows the level that you need to drop below before bed time. Ideally, you’ll probably drink a large cup of coffee/tea in the morning and then top it up with small cups throughout the day. One of the app’s neatest functions is that it warns you if you’re about to consume something that will leave you above the sleep threshold (in general, this means you shouldn’t drink a large cup of tea or coffee after midday). If you have built up a resistance to caffeine, or you’re particularly affected by it, you can alter the “optimal” and “sleep” values in Settings.

Read more at Caffeine Zone, or download it from the iTunes App Store

Update @ 08:57: There’s a similar app for Android called Caffeine Tracker — but it’ll cost you $1.