When it comes to the ownership rights to a song, the legal and ethical waters get a bit murky. Establishing the ownership of any creative work can be fraught with peril, although there are some basic copyright laws that do make things a little clearer. One might assume the songwriter himself or herself owns the exclusive rights to a song that he or she created, but that's not always the case in the professional music business.
A songwriter, much like any other literary composer, is automatically granted rights to a song the instant it is created. But this is considered to be more of an intellectual copyright until that song has been registered, transcribed in printed form, or otherwise established in a permanent medium (such as a recorded demo). If another musician learned the song's unique melody and lyrics, then deliberately claimed the song as his or her own, the original songwriter may have a difficult time proving his ownership of a song that was never recorded or published. Scenarios such as this can and do happen in the music industry, especially when songwriting teams split up or band members become solo artists.
Even though the original songwriter may own the intellectual rights to a song, he or she may not be in a position to control all of the possible uses of that song. Songwriters and musicians under contract to a studio may have to relinquish certain rights as part of their agreement. In that case, the studio itself may assume certain rights to ownership, particularly when it comes to derivative works such as sampling, covers by other artists, and compilation albums. Songs created by artists while under contract to a studio may be considered "work product," in the same sense that an engineer working for NASA or General Electric could not claim a patent for an invention created on company time.
There is also a separation between the performance rights to a song and the recording rights. Many times, the publisher of a song, which may or may not be the composer, controls the mechanical rights of that song. Producers and musicians interested in recording the song and releasing it on an album must obtain the mechanical rights to do so. This is one way an artist can exercise some control over the use of his or her music, especially when the artistic visions of the songwriter and interested parties could potentially clash. In some ways, whoever holds the mechanical rights to a song effectively controls the future of that song. Quite often, this is the original songwriter working as the head of his or her own music publishing company.