When You Need a License
Although purchasing a CD or a musical work gives the purchaser the right to privately listen to a song, it is required that you purchase a license for the public performance of a copyrighted song at an event. A public performance includes any use of a work at a venue open to the public or at any place where a substantial number of people will be present that are outside your normal circle of family and social acquaintances. For private social gatherings use of a song is likely acceptable; for larger public events you should consider hiring a DJ, who will already have licenses, or acquiring licenses individually.
There are a few common exclusions to when a work must be licensed for a public performance. These exclusions apply to songs in the public domain, the educational use of a song, use of a song in a place of worship or the use of a song in a restaurant or bar when that song is being played over broadcast media and the location in question adheres to strict size and speaker requirements. These exclusions have many limitations and you should contact a copyright attorney before attempting to play copyrighted music at an event under any exclusion.
Getting a License
The licensing agencies that hold the rights to the public performances of copyrighted works take their property very seriously, so it is extremely important to get the proper license if you intend to use a copyrighted song at a public event. In order to obtain a license to publicly perform a copyrighted song, you will need to contact the three performing rights agencies to determine which one holds the rights to the song you want to play. These agencies are ASCAP, BMI and SESAC.
In addition to the limited exclusions described above, the doctrine of fair use allows for a court defense for the public performance of a work if you can show the court that the nature and intention of your use was non-infringing, you only used a small amount of the copyrighted work, the nature of the work does not lend itself to a finding of infringement and your use of the work did not affect the intended market for the work. The fair-use doctrine is a court defense rather than a recognized exclusion to obtaining a license, so you should proceed with caution.