Foam insulation is a great way to reduce unwanted noise. It works similarly to earplugs, absorbing sound and keeping it from traveling outside or inside the home. Aerosol foam insulation is great for insulation, but it's not the best for soundproofing. Open-cell spray foam is better at absorbing sound than closed-cell foam, and it can reduce noise between rooms and homes.
However, it won't completely eliminate sound, and it won't muffle sound throughout the house. Egg-box type foam won't prevent sound from being transferred across walls or from leaving the room, but it will absorb some of the sound in the room and prevent it from resonating and amplifying. Closed-cell aerosol foam is not recommended for soundproofing a room, as it makes the house prone to echoes and transmits sound instead of absorbing it. The best way to achieve soundproofing effects is to use a combination of spray foam insulation and block insulation.
Open-cell foam is generally used to soundproof homes and buildings, as it is very affordable and has a lot of air bags inside that are great at absorbing sound. Spray foam can be very useful when it comes to soundproofing spaces, as it expands and covers the entire surface easily. According to an internal report by the NRC of Canada, there isn't much difference between fiberglass and aerosol foam when it comes to noise reduction, so open-cell spray foam may be the best option. As long as you don't want complete silence in your home, foam insulation can definitely help reduce noise from neighbors, passing trucks, or even from room to room.