Spices will keep for years if left whole. But the minute they are ground, they start deteriorating. That means that spices taste better, and are a better value, when bought whole and ground as needed. The process isn’t hard, but it does take a little time.
Most spice benefits from toasting before grinding – but not all. Black pepper, for instance, is good to go. Recipes will specify, but in general, the heat releases the spice oils, which changes their flavor, usually for the better. Use a dry pan, preferably made of cast iron, which conducts heat evenly. Add the spices to the pan and keep them moving by shaking the pan or stirring. This constant movement ensures the spices will toast evenly. As soon as they become fragrant, the toasting is done. Be careful, as these tiny seeds and berries can burn very quickly. Remove them from the heat and the pan ASAP. Remember, the pan is still hot and it will keep cooking the spices until you remove them.
Sometimes recipes will include heating the spices in liquid, so the toasting step can be omitted.
Next comes the grinding. Cool the spices before you grind them. They are easier to handle, and they emit fewer fumes.
A coffee grinder is a good tool for the smaller spices. It is small, which forces the spices through the blade more often than a larger food processor or blender does, producing a finer, more even grind. I recommend you get a separate grinder just for spices. I have had some mighty weird coffee after a particularly spicy kitchen escapade.
When I am feeling historic, I enjoy grinding in a mortar. The result is rougher, but more spiritually satisfying. (Culinary geeks, unite!) There is also a method the French call mignonette, in which whole spices are crushed by the flat bottom of a frying pan. Don’t whack the pan onto the spices like a fly swatter, but rather, use the pan to knead or rub the spices into submission. This is typically done with pepper, but it works for everything in a pinch. I like to do this when I am trying to impress people. Or when I am too lazy to dig out the machinery.