A bill to legalise same-sex marriage in NSW has been defeated by the narrowest possible margin, with its supporters crushed they couldn't win just one more vote.

The bill was voted down on Thursday by 21 votes to 19.

While a disappointment for some, it was a common-sense decision for others.

Premier Barry O'Farrell said on the eve of the bill's introduction to parliament last month that he wanted to see a national law rather than "patchwork" state legislation.

Under the bill, couples would have inferior rights on matters such as the custody of children and property settlement, Mr O'Farrell argued.

Christian Democrat Fred Nile credited the premier's statement as the decisive factor in the vote.

"He finally agreed to make that public statement and it did have the effect that I was hoping it would have on some of the wavering members of the coalition," Mr Nile told reporters.

He said he would be "celebrating the victory" at his own marriage in December.

Nationals MP Trevor Khan said he found the vote "very difficult to accept".

Mr Khan was part of a cross-party group that worked on the private members bill introduced to the upper house in October by Labor MP Penny Sharpe.

Ms Sharpe says the introduction of gay marriage is just a matter of time.

"We know communities are ahead of our parliaments on this," she said.

One major concern was the validity of the bill in the face of a possible High Court challenge.

Independent MP Alex Greenwich was also heartened.

"Today people were looking for excuses (to vote against the bill) outside of the moral questions around being gay," he said.

But strong community opposition to same-sex marriage was exposed during the debate when Labor MP Helen Westwood read out a "hate letter" she received.

The gay MP cried as she read the correspondence that stated: "the majority (of people) would rather see all queers burnt at the stake".

Australian Christian Lobby spokesman Lyle Shelton said it was time for people to "move on", saying that "each time parliament spends time debating this issue is a lost opportunity to debate policies at the heart of government".