The heat of a fire causes water inside a burning log to expand and become a pressured gas. When the gas has nowhere to go, it literally forces itself out of the wood and causes the pop and spark. These loud pops could be caused by just a small drop of water or several drops that have formed together and created a large section of gas.
While gas from evaporated water is the main cause of cracking and sparks in a fire, but other elements in the wood could also cause these to occur. Small pockets of air in the wood from termites or other creatures could become filled with smoke and pop from the pressure. Tree sap becomes so heated that it turns into a vapor and follows the same fate as the water vapor. Elements like metal, plastic or other materials that got mixed up with a wood pile can cause a pop or spark when they are heated too much.
Large sparks from the wood can land on objects outside the fireplace and cause fires. Use caution when your fireplace sparks often. Surround your fireplace with a glass protection screen to prevent the sparks from escaping. Use a fire poker to adjust the wood and prevent the sparks from shooting outward or straight up.
Using seasoned wood is the best way to avoid cracks and sparks in a fireplace. Seasoned wood has been drying out for over a year. This removes any moisture within the wood particles and makes it burn a lot cleaner than fresh-cut wood. When you purchase firewood, request seasoned wood rather than the fresh wood. If you purchase wood from a store, the label will indicate the seasoning process and how old the wood is. Look for a white interior on the wood for it to burn crackle free.