Epidemics and pandemics refer to the spread of infectious diseases among a population. The difference between an epidemic and a pandemic is two-fold. First a pandemic is normally used to indicate a far higher number of people affected than an epidemic, and a pandemic refers to a much larger region affected. In the most extreme case, the global population is affected by a pandemic.
An epidemic is defined by an illness or health-related issue that is showing up in more cases than would be normally expected. However, in the case of a pandemic, even more of the population is affected than in an epidemic.
Let's take a hypothetical example and assume several people contract the same flu-like symptoms in a particular area. Let's further assume that cases show up across the state, but the concentration remains localized in a few original cities. Some cases even turn up elsewhere in the nation, but the illness doesn't catch on elsewhere. In the hubs where it is seen the infection rate remains more than you would expect to normally see. This is a classic example of an epidemic.
Now let's take that same scenario but imagine the rate of infection started growing exponentially so that more and more cases were cropping up locally. When the rate of infection grows very fast it is likely, given favorable circumstances, that the epidemic grows into something more. Now we start seeing cases across the nation and the rate of infection is exceeding even that of an epidemic. It turns out in our hypothetical scenario that most of the population in the nation becomes affected by this flu. This is a pandemic.
To put a finer point on it, if the entire nation was affected but the rate of incidence never rose above that of an epidemic, it would still be considered an epidemic, even though the disease was nationwide.
Conversely, you might have a small population in a remote area of Africa, for example, that is nearly 100% affected by an illness or health problem. Because the incidence is so high, and the area relatively widespread in that it is affecting an entire population, this could be termed pandemic.
You can see with these subtle but significant differences how the terms might be confusing, but normally epidemics that grow out of hand due to the nature of the disease and other factors, turn into pandemics.
A pandemic may be regionally localized if it involves more cases than a simple epidemic; and an epidemic may be widespread if not enough of the population is affected to term it pandemic. Though in this latter case, you might still see it termed pandemic by some, just because the geographical area is so widespread.