A recording contract (commonly called a record contract or record deal) is a legal agreement between a record label and a recording artist (or group), where the artist makes a record (or series of records) for the label to sell and promote. Artists under contract are normally only allowed to record for that label exclusively; guest appearances on other artists' records will carry a notice "By courtesy of (the name of the label)", and that label may receive a percentage of sales.
Labels typically own the copyright in the records their artists make, and also the master copies of those records. An exception is when a label makes a distribution deal with an artist; in this case, the artist, their manager, or another party may own the copyright (and masters), while the record is licensed exclusively to the label for a set period of time. Promotion is a key factor in the success of a record, and is largely the label's responsibility, as is proper distribution of records.
While initial recording deals usually yield a smaller percentage of royalties to the artists, subsequent (or re-negotiated) deals can result in much greater profit, or profit potential. A few acts, such as Madonna, Michael Jackson, R.E.M., U2, and Janet Jackson, among others, have signed multimillion-dollar deals. Whitney Houston signed a $100 million deal with BMG to deliver just six albums, the largest recording deal at the time. Robbie Williams signed an £80m (US$125m) contract with EMI.  For many other artists, though, for the millions to become tangible, hit albums meeting or exceeding their previous sales figures must follow. Recording contracts may include opt-out clauses for the label in the event an act's popularity dips or the act releases non-hit albums under the deal. For instance, Mariah Carey was dropped by Virgin Records and her $100 million recording deal cancelled after her first album released by the label sold poorly. 
Record companies put forth huge sums of money to produce, release, and promote an album. Recording time, manufacturing, packaging, photos, distribution, marketing, and music videos are just some of the areas where the label must spend money on an act it has signed. The label usually absorbs these expenses, but in some artists' contracts, some of this money may be due back to the label, unless otherwise worded. Advances (upfront money that is paid directly to a recording artist) are normally always owed back to the label. Once (and if) the advance has been paid back from record sales, the artist then begins to see royalty payments for additional sales. Advancing an act money is a risk the label endures as it does not know how well the act's album will sell. Capitol Records suspended Linda Ronstadt's contract in the early 1970s, as Capitol had spent more money on Ronstadt then it had yielded. She continued to tour partly to pay Capitol back for her 1960s deal, and a string of hits in the mid-1970s allowed her to finally clear the debt. Record companies expect to make a profit, and little concern themselves with a given performer's lack of business or financial savvy, as artists such as George Michael have discovered. "Walking out" on a deal is very difficult or nearly impossible, as is attempting to strike a new deal without completing an old one. Donna Summer signed a new deal with Geffen Records in 1980, and released two albums on Geffen. She was then told by her previous label, Polygram Records, that she owed them another album, per her agreement. She recorded and delivered an album to Polygram that the label released, and it became a hit. Summer then went back to recording for Geffen Records for her next project. The Mamas & the Papas were forced into a reunion, years after their 1968 breakup, by the letter of their Dunhill Records contract, which required one more album to be completed -which became 1971's People Like Us.
Record companies will generally increase royalty rates or give artistic freedom to get acts to re-sign contracts with them once the original deal has been fulfilled. Established acts may otherwise go where they see better opportunity. During 1980, Diana Ross released her album diana, which fulfilled her contract with Motown Records. The album spawned three US hits (a #1 and two top tens) and sold 10 million copies worldwide. Ross, however, felt she was never fairly compensated by Motown for her work with The Supremes or her solo releases. When RCA Records offered her $20 million to sign with them, Ross gave Motown the chance to match the deal, or at least offer something almost comparable. Motown, believing Ross's solo career was too up-and-down, and not seeing any reason to now compensate her for her earlier Supremes work, offered $3 million. Split with the decision to remain with the label that made her famous, or sign a deal with a company that was willing to pay her what she felt she was worth, she ultimately signed with RCA. That $20 million deal was the biggest recording contract at the time. She had signed with RCA for North America only, she signed a separate longterm contract with Capitol/EMI for international territories. That contractual amount was never officially released. However, it is believed to be as much as $20 more million and she has remained currently signed with them for over 30 years and has produced many more successful recordings internationally including her multi-platinum 1991 release, The Force Behind the Power and an even greater success with a greatest hits compilation, One Woman: The Ultimate Collection that sold over 1.5 million in the United Kingdom alone, spending several weeks at #1.
There are plenty examples of recording contracts available in music business guides, legal texts and also online. 
When recordings go out of print, this typically happens because either the label has decided that continuing to sell (or distribute) the record will not be profitable, or the licensing agreement with the artist has expired. (Labels may also stop distribution as a punitive measure, if an artist fails to comply with their contract, or as a strategic measure if negotiations for a new one prove difficult.) Record labels can also become bankrupt like any business, and their masters and copyrights sold or traded as part of their assets. (Occasionally these are purchased by the artists themselves.)
Recording artists signed to a failed label can find themselves in limbo, unable to record for anyone but a company that is out of business (and thus cannot sell or distribute their records), and with their existing works unavailable for sale. When one label "buys out" another (or a label is purchased by an outside party), any existing copyrights and contracts held (and masters, if owned by the label) normally go with the sale. This often benefits recording artists, but not always.
Distribution deals are often renewed, but occasionally the label and the copyright owner cannot come to terms for a renewal. The reason is usually that one party expects too much money, or too large a percentage of profits, to suit the other.