Daniel McCArthur, general manager of Ashers bakery in Belfast, and his wife Amy have been in legal battle with gay rights activist Gareth Lee since 2014, when he asked them to ice a cake with the slogan 'Support Gay Marriage'. They refused because they said it contradicted with their religious views.
Justice Lady Hale said: "The bakers did not refuse to fulfil his order because of sexual orientation.
"They would have refused to make such a cake for any customer, irrespective of their sexual orientation.
"Their objection was to the message on the cake, not to the personal characteristics of Mr Lee or of anyone else with whom he was associated".
She also addressed the freedoms the couple based their claims on from European Convention of Human Rights, saying: "The freedom to not express an opinion which one does not hold is also protected by Article 10 of the convention...
"This court has held that 'nobody should be forced to have or express a political opinion in which he does not believe".
The judgment has set a precedent that one can refuse to promote a belief they do not hold as long as they are not doing it because of the person who asked them.
Lady Hale continued: "The bakers could not refuse to supply their goods to Mr Lee because he was a gay man or supported at marriage, but that is quite different from obliging them to supply a cake over with a message with which they profoundly disagreed."
She concludes: "It is deeply humiliating, and an affront to human dignity, to deny someone a service because of that person's race, gender, sexual orientation, religion or beliefs but that is not what happened in this case".
The Supreme Court judges have overturned previous court judgements which stated Ashers was unlawful.
The Equality Commission first took up Mr Lee's case in 2014 and it went to court in Belfast with them claiming the McArthurs had acted with discrimination.
The couple, backed by the Christian Institute, argued that they had served the customer in the past and would in the future but that the statement in favour of gay marriage went against their personal beliefs and that they would not make the same cake for a straight person.
The initial court hearing in Northern Ireland ruled in Gareth Lee's favour, saying they had unlawfully discriminated. Ashers Bakery Company launched an appeal to the Court of Appeal in Northern Ireland but lost - the original ruling was upheld in October 2016.
They then announced they would take it higher, to the UK Supreme court and campaign for a different decision, which has been announced today in their favour.
Stay up to date with the latest news stories from a Christian perspective. Sign up to our daily newsletter and receive more stories like this straight to your inbox every morning.