If I left food out of the refrigerator for some period of time, is it still safe? If I left it out too long, can I salvage it by cooking it more?
How to know if food left at room temperature is still safe to eat
food-safetyrefrigerator
Related Solutions
hobodave's answer is most of the way there but I think it understates the importance of protein toxins. With the vast majority of foodborne illnesses, the bacteria aren't particularly harmful at all; what you need to worry about is the protein toxins they produce.
E.Coli - probably the most well-known form of food poisoning along with Salmonella - is actually a harmless bacteria that already lives in your lower intestine. But there is a particular strain of E.Coli, notably O157:H7, that is primarily associated with food poisoning. The reason? It produces what's called a Shiga-like Toxin.
E.Coli contamination is actually dangerous on two fronts. Because the bacteria are so well-adapted to surviving in the human digestive system (as I pointed out earlier, that's their primary habitat), ingesting even a relatively small number of the bacteria will result in them multiplying and producing those toxins in your gut (and the rest of the way down). This is why it normally takes several days for you to feel the effects of this type of food poisoning; that's how long it takes for them to produce the toxins in sufficient quantity for your body to notice.
But they don't need to be in your gut to produce those toxins; a piece of meat at room temperature provides good enough conditions and more than enough raw material for them reproduce and emit those same toxins. So if you leave it sitting out too long, then it really doesn't matter how many bacteria you kill, you are going to end up with E.Coli poisoning fast, because you don't even need to wait for them to produce the toxins; they're already there.
The problem is that you can't "kill" a protein toxin with a brief burst of heat because a protein isn't alive. It's just a protein. The temperatures and times needed to destroy that toxin would be similar to the temperatures and times needed to destroy all of the protein in the food, draining all the nutrition value and quite possibly turning it into a lump of charcoal.
Salmonella seems to be a fountain of misinformation with all sorts of people saying that it doesn't produce toxins. This simply isn't true. Inside the host it produces what's called an AvrA toxin (which isn't "toxic" per se, but allows the bacteria to grow to larger numbers), and some strains can also produce a CdtB toxin, which is highly toxic. (Apparently there's also a similar toxin produced by other strains.) I'll be honest, a lot of the medical mumbo-jumbo is way beyond my ability to comprehend, but it seems that a lot of the public confusion comes from the fact that salmonella can do some nasty things even without the toxins - but that doesn't mean that the toxins themselves can't do plenty of damage even if you manage to kill the bacteria.
The same applies to many other types of dangerous bacteria; C.diptheriae produce the diphtheria toxin, C.botulinum produce the botulinum toxin (botulism); even the infamous mad cow disease was, as far as we know, caused by a protein, not a bacteria, which is why it was able to be transmitted to humans even through cooked beef.
Are protein toxins the only reason why the USDA insists on a maximum 4-hour cumulative danger zone? Probably not. As hobodave says, the more the bacteria multiply, the harder is to kill all of them, even at high temperatures. The figure of 74° C / 165° F that the food agencies give us for poultry is not going to kill exactly 100% of all the bacteria, and if it only kills - I'm just throwing out a number here - 99.999% of them, that may be good enough for relatively fresh poultry but won't be enough if you've got a whole bacterial colony to worry about.
We can only speculate as to exactly what's entailed by the "danger zone" but my guess is that it's actually a combination of statistics, probabilities, and safety margins, which include, but are not limited to, the effects of protein toxins.
Pie is a good example: fruit pie tends to keep for a good while at room temperature. I have found many sites which stridently claim this not to be the case, and many grocery stores that leave their bakery pies at room temp for about three days (even psycho Mrs. Cookwell says 2 days is fine). I'm siding with the grocery stores. Nut pies tend to last longer still, because they're drier: the presence of dairy and eggs is counteracted by the higher concentration of sugar.
Likewise cake, though it can vary depending on your frosting...The more things besides fat and sugar in your frosting, the more it needs to be refrigerated. In most cases cake will stay edible longer than you'd want to eat it. Again, grocery stores only bother to refrigerate decorated cakes, or ones with cream cheese icing.
Most store bought condiments are fine at room temperature. Obviously not mayonnaise, or anything creamy, but ketchup, mustard, A-1, worstershire...They last a good long time unrefrigerated. Likewise soy sauce, fish sauce, and some of the more popular asian condiments.
I've never seen a pepper sauce (e.g. Tabasco) that needs refrigeration, and they'll last for years, though the color starts going off after a while.
There is no bacterial risk to leaving fruits and vegetables out, but this will dramatically increase the rate of spoilage. The exceptions are root vegetables, and bananas. Root vegetables will last a long time in a cool dark place, so just lump 'em in your garage if you're not going to eat them in the next week or two. And bananas will go south at the same rate regardless (though you can freeze them for future banana bread).
Fresh eggs (like, straight from the chicken) will last a couple of weeks without refrigeration (make sure they're not fertilized, or you may wake up to find baby chickens in your kitchen). The rule of thumb is "Every day unrefrigerated is like 5 days refrigerated." Once eggs are cracked, you should use them immediately.
I'd trust store bought eggs left out on the counter to eat, though its not good to let refrigerated eggs get warm again. Eggs have a wide array of natural antimicrobial tendencies, though the processing store bought eggs go through removes some of this. (citation). An easy way to test for internal contamination is to see if the egg floats in water. If it floats, toss it.
Bacon grease keeps a long time unrefrigerated, as does any sort of fat really, as long as it's strained and filtered. With fats you're more worried about them going rancid, which is a function of light and air (its a type of oxidation), so store your fat in a dark place, in a sealed container. (citation)
Butter can last several days unrefrigerated (it should be covered). I'd say as much as a week, but I have no way of knowing because it never lasts that long. It's much more likely to oxidize (see above) and go rancid than to pick up a significant bacterial colony.
Best Answer
When in Doubt, Throw it Out!
You cannot always see or smell bacterial contamination. Mold that appears to be growing only on the surface may grow invisible roots into softer foods. Do not rely on a visual inspection or "smell test" to tell you whether or not a food is safe. It's not worth the risk - food poisoning can be much, much worse than an upset stomach.
The Danger Zone
Per the USDA guidelines, potentially hazardous food that stays in the temperature "danger zone", 40-140 °F (4-60 °C), for more than 2 hours should be discarded. For temperatures above 90°F (32°C), the limit is 1 hour.*
Potentially hazardous foods are those foods that spoil most easily, such as unshelled eggs, raw meats, fish, shell fish, dairy products, almost all cooked foods.
This time is cumulative, so it includes time bringing the food home from the grocery store, time before cooking, time after cooking, and so on. The reason is that while cooking may destroy bacteria or other pathogens, it doesn't always destroy the toxins that they have produced.
In general, regarding perishable foods like meat, most dairy, unshelled eggs and shell eggs (in the US), cooked casseroles, and so on: if the food (or its perishable components) have been at room temperature for more than two hours, you should discard that food.
To avoid the danger zone, keep cooked food hot until ready to eat, then refrigerate immediately. Separate large items into smaller containers to help them to cool more quickly. If you’re defrosting something, do it in the fridge or under cold running water.
If you can be certain that the food was not in the danger zone, then yes, it is safe. For example, if you left a large chunk of frozen meat out and it is still frozen solid (including the surface) when you come back to it, it was not in the danger zone.
Why is it so strict? / Why didn't I get sick?
These guidelines are about making sure you don't get a foodborne illness, i.e. reducing the risk to where it's so small as to not be an issue. So if you break the rules, e.g. eating food that's been left at room temperature for 8 hours, that doesn't mean you will get sick, just that you're taking a risk.
Why does cooking not completely "reset the clock"?
Some bacteria leave behind harmful protein toxins that cannot be "killed" (denatured) by cooking. Cooking food is only effective against live organisms, not their toxic waste products. Spoiled food cannot be cooked back to safety and must be discarded.
Cooking is pasteurization, not sterilization. Pasteurization means killing most microbes, so as to render the food safe for human consumption. Sterilization methods (e.g. pressure-canning and irradiation) are the only safe methods for longer-term room-temperature storage. Otherwise, the danger zone rules always apply.
Even sterilized food can only remain sterile under an airtight seal, e.g. when properly canned or vacuum-sealed. Once it is opened, it is no longer sterile. Air contains countless bacteria and molds, and their spores, which will readily re-colonize any suitable environment they encounter. Cooked food tends to be an ideal medium for growth.
What can I leave out longer?
For foods that aren't potentially hazardous as described above, there's no solid rule, but things are generally safe for much longer than the 2 hours given above. For example, things which are sold at room temperature (e.g. fresh produce, bread, or cookies) are most likely safe at least all day or overnight if not for days or even months. You can find guidelines for common things at StillTasty.
Regulation and Risks
Follow the guidelines set out by reputable regulatory agencies, especially when serving others. Local organizations include:
Other regulatory sources apply in other parts of the word, but major food safety organizations usually agree in essence (if not in complete detail) on most issues.
Failure to follow reputable guidelines is irresponsible if you are serving guests, and failure to follow your specific local codes is likely to be illegal if you are serving customers.
Health codes tend to be very conservative, to fully protect the community. You have the right to take risks on yourself by ignoring their recommendations, but please do not risk the safety of others.
Again, When in Doubt...
Once again, if you suspect spoilage or contamination, please, throw it out.
* Note: this is the USDA's rule. Other agencies may have variations on it. Additionally, government agencies generally make very conservative recommendations - they're trying to make sure that no one who follows the rules gets sick. Breaking the rules means maybe taking on some risk. That's up to you - just remember, eventually someone gets unlucky, and food poisoning is not fun.
Helpful Resources
Further Reading/Frequently Asked