You may as well ask how long a pet lives. Depends on the pet; depends on the powder. Some guys have successfully fired 30-06 dating back to the late 1920s. Others have had post-WWII loads from the late 1940s blow a Garand up (not easy to do). Many more have simply experienced a catsneeze load or a fizzle.
So, here's the problem: Powder starts going bad the day it is made. Heat makes molecules vibrate and those vibrations can randomly combine to pass the potential energy release threshold of an individual molecule, causing it to break down. Thus, there are individual molecules of nitrocellulose or nitroglycerin breaking down here and there all around the powder mass. The powder mass has an astronomical number of molecules, so this constant random breakdown is not enough to appreciably weaken the powder by itself. Not in several human lifetimes, anyway. What causes significant weakening is the acid produced by that breakdown is also able to break other molecules down whose acid products, in turn, make still other molecules break down and so on in a kind snowball effect. As a result, pure nitrocellulose and nitroglycerin don't age well. So what the powder maker does to prevent that is to include a chemical called a stabilizer that neutralizes the acid byproducts as soon as they appear, thus preventing them from damaging other molecules. The stabilizing neutralizer is commonly diphenylamine, but calcium carbonate and other ingredients have been used. And this works great until the stabilizer is used up. At that point, the breakdown accelerates.
So, the age of the powder, as it is associated with consumption of the stabilizer is what makes powder go bad. The temperature at which the powder is stored has a big effect. Single lots of single-base powders can be stored at root cellar temperatures for a very long time. The military puts a 45-year stockpile limit on it. Double-base powders go more quickly, and 20-years is a military stockpile number for them. And this is in basement temperatures (bunkers sunk into the ground). If you heat powder, the breakdown follows the Ahrenius function, more or less, doubling the breakdown rate about every 10°C (18°F) or so. As a result, in tests intended to cause a powder to break down, 140° will do it to spherical powders in about a year and a half.
But just when you think all will be well if you keep your powder cool, there's a catch (isn't there always). When powders come off the production line (bulk grade) they are tested for burn rate because this is something very difficult to control exactly in an affordable process. For the powders made for the handloading market (canister grade), because handloaders don't typically have pressure measuring gear and depend on recipes in load data books to get in the correct pressure range, the burn rate has to be controlled more tightly than the powder manufacturing process can achieve. To solve this, when a bulk lot doesn't fall within the tolerance that is safe to use with published load data, it is blended with held-back previous lots that are either faster or slower burning (as needed) to adjust the overall burn rate of the new lot. Now how long do you suppose that powder will last? It depends on how much stabilizer was left in the held-back lots. In other words, the oldest powder in the blend generally determines the remaining life expectancy. How old is that? How do you know? You don't. This is why you need to check powder every time you use it.
In general:
Check the smell. If it smells like nitric acid instead of the normal ethyl ether solvent smell, it is going bad. Nitric acid has an acrid smell, like vinegar and muriatic acid do, but, just as those two have dissimilar smells, so, too is nitric acid's scent unique, and "acrid" is about the only characteristic those acid scents all have in common. But you'll notice it is different from normal powder smell right away, and if you compare the smell to that of other powders you have, you'll know right away that it is wrong.
Another symptom that can develop is the powder looks oily and is clumping together. It should look dry and flow well when you pour it.
Another symptom you can have is a dry appearing powder, but with red dust mixed with it. Pour some out on a sheet of white paper and jostle it around a little and then pour it back into the container. If red dust is left behind on the paper, you have a problem.
Finally, own a chronograph and keep a notebook. If your best load from a lot of powder suddenly changes velocity when you've changed nothing else, including the test conditions, that can be a warning sign. Usually, the velocity goes down, but occasionally a powder formulation (often spherical) will start to raise pressure by destroying its deterrent coatings faster than the underlying powder is destroyed, giving the remaining powder a faster burn rate, so it makes very high peak pressure. That is what can damage a gun.