In his darkest moments last year when he doubted if he would ever get back to full fitness following his knee injury, Roger Federer clung on to one thought -- he still had the game to maybe sneak another grand slam title.

He was right.

Federer, who missed the Rio Olympics and U.S. Open last year while he recovered, outlasted Rafa Nadal in five sets on Sunday to clinch his 18th grand slam title at Melbourne Park, four and half years after his last.

"There's never a guarantee but I was always positive," the 35-year-old told the Australian Open website about how he got through the doldrums last year.

"It was about staying calm and believing the work's paying off and that the variety I have in my game maybe allows me to maybe sneak in one or a couple."

Federer said his belief was also based on the fact that until his injury, he was still competing well, reaching two grand slam finals in 2015 and two semi-finals in 2016.

"If you look back at my results, in 2016 and especially in 2015, I think I played some really good tennis and some good attacking tennis," he said.

"Honestly I believed I could do it, the question was how's Novak (Djokovic) going to play, how's Andy (Murray) going to play, Rafa and everybody.

"I knew it was going to be hard because they're not getting any worse and I am getting older so I don't have much time."

With Murray and Djokovic both going out before the quarter-finals at Melbourne Park, Federer took his chance, beating Kei Nishikori, Stan Wawrinka and then Nadal.

Federer, who had promised to "party like rock stars" after the victory was bleary eyed when he turned up to the champions' photo shoot in Melbourne on Monday.

"Waking up, I don't know if I slept, even if I did sleep," said Federer. "I had to look at the highlights again to remember how close the match was again."

Federer climbed to 10th in the rankings after his win and added it was his self belief when he had been trailling 3-1 in the final set that had helped him to victory.

"I said to myself, 'I'm all in'," he said. "I still had the mindset that I had nothing to lose.

"I think I was able to shuffle all those things around in my head and believe until the very end I could actually turn it around and the last four games were just epic, so I couldn't be happier."