Fill the gaps
The best gap-filling material of all is real wood. Choose that option when the void is large enough and regular in shape, like the one shown here.
Use a chisel to take a sliver from another piece of matching wood, making it deeper than the gap. Rub the sides of the sliver on sandpaper until it fits the width of the gap perfectly. Force glue into the opening with a knife or a piece of paper, then slip the filler into place.
After the glue dries, use the flat face of a chisel to trim the protruding filler piece flush with the surface of your project. Follow that with light sanding.
Fill the gaps
Despite our best efforts, we often have to deal with gaps at joint lines, cracks in the wood, nail holes, and other surface flaws. With the proper techniques, you can make those shortcomings disappear.
Whenever possible, fill wide gaps and cracks with slivers of the same kind of wood used in your project, as shown in photo. You can buy various brands of paste-like wood filler that will disguise smaller gaps. It won't take stain like wood, but a repair that runs parallel to the grain will blend in nicely.
Holes call for different tactics. Putties and sticks of all kinds come in various colors and are designed to match your wood. Unfortunately, as they dry, the color tends to leach into the surrounding wood. Like the fillers, none of them will take stain the same as the wood in your project. So don't use them during your preparation work. Wait until you've stained and applied a coat of finish, then use a putty that matches the finish color.