Malcolm Turnbull has urged G20 leaders to take a strong stand against terrorists on the battlefield and online.

The prime minister told a session of the Hamburg summit on Friday there needed to be a show of collective resolve to defeat violent extremism.

Such action was justified not only in global and regional terms, but also in each country's national interest.

It is understood Mr Turnbull's call for greater powers for law enforcement to deal with extremists exploiting new encrypted communications apps and social media was well received.

"I understand the legal issues," he told the meeting.

"But we need to say with one voice to Silicon Valley and its emulators: 'You have got to find a way to ensure that these wonderful platforms are not used as dark places for criminals and terrorists to hide'."

He said it was the first duty of governments to keep their citizens safe.

The prime minister outlined his past experience in setting up the Ozemail internet business in Australia, as he declared his commitment to freedom of speech.

But while a strong libertarian attitude such as that in the US was justifiable, countries could not be blind to the fact that the best defence against terrorism is to know about attacks in advance of them being carried out.

He described violent Islamist extremism as a crisis in the Muslim world and praised Indonesian President Joko Widodo for his leadership in the region.

The outbreak of violence in the Philippines was a wake-up call in terms of the risks from the spread of extremism.

Mr Turnbull later discussed the session with US President Donald Trump as they headed to the traditional "family photo" session involving all of the leaders.