Barack Obama told an audience in Brazil that "our gun laws in the United States don’t make much sense" and claimed machine guns could be bought legally online.

The former president, 57, said the most difficult day of his eight years in the White House was after the 2012 school shooting in Newtown, Conn., when 20 elementary students and six staff were shot dead.

"And my daughters were only a little bit older than these young children that have been shot, and I had to go and comfort the parents. And some of you may be aware our gun laws in the United States don’t make much sense. Anybody can buy any weapon any time," Obama said to an applause.

"You know, without much, if any, regulation, they can buy it over the internet, they can buy machine guns. And for me, having to speak to parents who have lost a child, just two days or a day after it had happened, and not being able to assure them that that would change, that we would fix this — I couldn’t bring their children back, but I couldn’t even promise them that we would change the law so this didn’t happen to somebody else’s children," he said.

[Also read: New Zealand prime minister: 'I do not understand' US lack of action on gun control]

There are about 300 federal and state gun laws that regulate the sale and acquisition of firearms in the United States. When it comes to internet gun sales, the firearm is sent to a gun dealer who holds a federal firearms license. An FBI background check is then conducted before the firearm is transferred to the buyer.

The buying and selling of new machine guns, which are capable of firing more than one bullet per trigger pull, has been banned since 1986 as the result of an amendment in the Firearms Owners' Protection Act. Machine guns that were made before 1986 were grandfathered in and can still be purchased, but they are heavily regulated and require an additional license and fees.