Scientists have discovered when the kangaroo learned to hop — and it's a lot earlier than previously thought.

According to new fossils, the origin of the famous kangaroo gait goes back 20 million years, BBC reported.

Living kangaroos are the only large mammal to use hopping on two legs as their main form of locomotion.

The extinct cousins of modern kangaroos could also hop, according to a study of their fossilized foot bones, as well as moving on four legs and climbing trees.

The rare kangaroo fossils were found at Riversleigh in the north-west of Queensland in Australia.

The site is a treasure trove of animal remains, including marsupials, bats, lizards, snakes, crocodiles and birds.

"It's one of the few snapshots we have of the evolution of marsupials in Australasia in deep time," said study researcher Dr Benjamin Kear, of Uppsala University in Sweden.

Kangaroos can quickly cover large distances using their distinctive gait, which is most effective in open habitats such as deserts and grasslands.

The long-held view has been that the animals evolved the ability to hop to take advantage of a change in the climate, which brought drier conditions and the spread of grasslands.

However the research, published in the journal Royal Society Open Science, suggests the story isn't that simple.

Geometric modelling shows the ancient extinct cousins of modern kangaroos could use the same range of gaits as living kangaroos.

Evidence, said the scientists, that the kangaroo has had the ability to hop for many millions of years.

"It all points towards an extremely successful animal, that's superbly adapted to its environment and a whole range of habitats and ecosystems and it's why kangaroos are so successful today," said Kear.

"It's one of the most biologically weird and wonderful animals you're likely to find."