The Happy Birthday song has finally been ruled as belonging to the public domain, but did you know of its tangled history?

On June 27, 1859, teacher Mildred Hill was born. You may not know her name but you will almost certainly have sung the song she helped write. Hill was the co-composer of Happy Birthday To You, originally called Good Morning To All, which is the song millions of people sing around a candlelit cake. It was first published in a songbook 90 years ago, on March 4. Although by 1924 the recognisable melody had been sung in American primary schools for nearly three decades, the publication was to trigger almost a century of legal wranglings which would result in Happy Birthday To You being one of the most lucrative songs of all time.

Even though nobody knows who actually wrote Happy Birthday's lyrics, until this week, Warner Music contentiously owns the copyright to the song in its entirety. The media giant has therefore been earning millions from people celebrating their birthdays for a quarter of a century. Walt Disney had to pay $5,000 to use it in a parade and the royalties charge on a scene of Martin Luther King celebrating his birthday in civil rights documentary Eyes on the Prize was so high that it never made it to DVD. More recently, the makers of the 2008 documentary No Subtitles Necessary: Laszlo & Vilmos, about the Hungarian cinematographers, paid $5000 to use the music in their film.

The Mars Curiosity Rover sang Happy Birthday to the surface of Mars a year after it landed Credit: Reuters/NASA

To sing Happy Birthday in a restaurant, at a concert or public place, royalties had to be paid. The most recent exception to the rule, it would seem, is if you sing it on Mars - as Curiosity Rover did to the surface of the planet last August, a year after it landed.

The familiar six-note tune and original similar, but importantly not birthday-related, lyrics were the work of two sisters, Mildred and Patty Hill, who composed Good Morning To All in 1893 to sing to their pupils every day. The Hill's lyrics wished listeners a 'good morning' where 'happy birthday' would later appear, and in this format the song made its way around Kentucky kindergartens and primary schools in the late 19th century.

The Hill sisters, possibly forseeing of the copyright battles to come, instructed the trainee teachers they shared the song with never to write it down. However, in around 1911 the word 'birthday' started to sneak its way into versions of the tune and it was first published next to the melody on this day in 1924.

The original sheet music for Good Morning to all Credit: Reuters

It didn't take long for the song to appear in the then-new sound films and on radio airwaves, entirely without royalties; in 1931 Happy Birthday appeared in the Broadway musical The Band Wagon. After Western Union used it as a stunt in their first ever "singing telegram" two years later and another appearance on Broadway, the third Hill sister, Jessica, took a stand and secured the copyright of Happy Birthday in 1934, thanks to its similarities to Good Morning To All.

The next year, the first copyrighted version of Happy Birthday was published by Clayton F. Summy Company. The Hills were to have rights over the song if it was sung for profit until 1991, and this was extended under current law until 2030. In 1988, after a series of acquisitions, Warner Music became owners of the song and benefited from its reported $2 million of royalties per year. The Hill Foundation, set up in the sisters' honour, has collected half of all royalties since 1893, with some going to their nephew Archibald, after Patty's death in 1946.

Many have argued that Happy Birthday belongs in the public domain. The best case was put forward by Robert Brauneis in his 2010 paper, Copywright and the World's Most Popular Song. Brauneis used more than 200 documents from six historical archives from across America, to put the Hills' ownership of the melody into dispute and show that the writer of the lyrics has never been recorded. Even if the Hills really did own the song, they didn't properly renew the copyright in the Sixties.

Top 65 Happy Songs

Last summer, a filmmaker called Jennifer Nelson filed a lawsuit against Warner Music after they charged her $1500 to make a film about the song and include a clip of it. Finally, the courts will decide once and for all who own Happy Birthday.

The dispute has rumbled on for two years, but closed on Tuesday, a US federal judge ruled that Warner Music does not hold a valid compyright to the song – and the company were asked to pay $5 million in licensing fees.

The case's direction changed earlier in the summer with a piece of evidence lawyers arguing against Warner Music say is a "smoking gun": a songbook from 1922 that includes the Happy Birthday tune and lyrics without any copyright notice. It's proof, they say, that the song has been in the public domain for decades.

Although Warner filed a motion opposing the request for a judgement based on this new evidence, the plaintiffs were "prepared to argue that Warner knowingly hid the songbook."

The history of Happy Birthday A happy melody is born Sisters Mildred and Patty Hill compose 'Good Morning To All' to sing to their pupils every day. The lyrics go: "Good morning to you, Good morning to you, Good morning, dear children, Good morning to all". Birthday lyrics sneak in The word 'birthday' starts to sneak its way into versions of the tune - perfect for singing at parties. Happy Birthday appears in print The 'Happy Birthday' lyrics are published next to the melody for the first time. The song hits screen and stage It doesn't take long for the song to appear in films and on radio airwaves - entirely without royalties. In 1931 Happy Birthday appears in the Broadway musical The Band Wagon. Copyright secured After more appearances in the public domain the third Hill sister, Jessica, takes a stand and secures the copyright of Happy Birthday, thanks to its similarities to Good Morning To All. Party song profits The first copyrighted version of Happy Birthday is published by Clayton F. Summy Company. The Hills have rights over the song if it is sung for profit until 1991 (this is later extended until 2030). Marilyn serenades the President Reuters Marilyn Monroe tweaks the lyrics to sing "Happy Birthday, Mr. President" for President John F. Kennedy at a celebration of his forty-fifth birthday. It has since become one of the most famous renditions of the song. Warner owns Happy Birthday Warner Music become owners of the song and benefit from its reported $2 million annual royalties. The Hill Foundation, set up in the sisters' honour, has collected half of all royalties since 1893, with some going to their nephew Archibald, after Patty's death in 1946. Questions raised over ownership Robert Brauneis publishes his paper, 'Copyright and the World's Most Popular Song', bringing the Hills' ownership of the melody into dispute. Happy Birthday goes to court Filmmaker Jennifer Nelson files a lawsuit against Warner Music after they charged her $1500 to make a film about the song and include a clip of it. Happy Birthday becomes royalty-free A US judge rules 'Happy Birthday to you' is not under copyright. The ruling means royalties will no longer have to be paid to Warner Music for use of the popular song.

Now Happy Birthday has returned to the public domain, you can expect to hear it far more frequently on films, adverts and TV shows.