First step: use vegetable shortening or another thick grease (not oil) to smear your pan thoroughly all over. Don’t leave chunks – it should be a clear, even coating, just enough for the flour to stick to it. This is messy work but I find it easiest to do with my hands, washing thoroughly before and after.
Next, carefully put a little bit of flour into the pan – 2 Tablespoons is almost always enough – and gently shake to coat the grease, turning gently to coat the rim evenly as well. Tap the residual flour out into the next pan and continue until all the pans you’re using are coated evenly. I usually end up tossing a bit of the flour in the trash, since I don’t want to get any shortening into the flour bin.
If you get a nice even layer of flour, your cakes will come out of the pans much more easily (while warm, you may still need help from a flexible thin spatula or knife, but follow the recipe directions) If you end up with too much flour it’s likely to stick to your cake at the bottom in lumps.
If you’re baking a chocolate cake, you could mix a teaspoon or so of cocoa powder into the flour to make sure it doesn’t leave white streaks on your cake.
I don’t like to do this to muffin tins because it’s very complicated. I’d rather rely on spray oil or use papers in that situation.