Image copyright Lionel Lauret

Whales are extremely shy animals, making it hard to study them in their natural habitat. But a group of marine scientists has managed to record their behaviour up-close by freediving with humpbacks and sperm whales.

I'm floating in the Indian Ocean, six miles off the north-east coast of Sri Lanka. A sperm whale and her calf are facing me, 150ft (45m) away.

I can see them swimming towards me, hissing, blowing steam and clicking loudly like a pneumatic drill.

"Don't swim, don't move. They're watching us," whispers my guide Hanli Prinsloo.

She grabs my hand and pulls me beneath the surface where we watch a hazy black mass materialise. Details gradually emerge: a fin, a gaping mouth, a patch of white. An eye, sunk low on a knotted head, peers in our direction.

Image copyright Frederic Buyle

The mother is the size of a school bus - together, they look like submerged islands.

I never wanted to swim with sperm whales. I'm not an adrenaline junky with a death wish and yet, against my better judgement, and my mother's protestations, I found myself floating in the open sea with a group of marine mammal scientists from Dare Win (Database Regional Whales and Dolphins), an independent non-profit research programme started by Fabrice Schnoller, a former lumber store owner from Reunion Island - a French territory in the Indian Ocean.

The gurgle of scuba equipment, submarines and robots that are normally used to study marine life tend to spook whales. To avoid scaring them, the Dare Win team have abandoned much of this technology and use freediving techniques instead, using only a mask, flippers, and a single breath of air to dive dozens of feet deep into the ocean.

Image copyright Frederic Buyle Image caption A Dare Win researcher recording sperm whale behaviour

With just one breath it's possible for experienced freedivers to stay underwater for more than four minutes. Sperm whales and humpback whales (as in the top picture) are often attracted to the freedivers who look like no other marine mammal - and sometimes, with a little luck, welcome the divers into their pods for hours at a time.

Other people have dived with sperm whales, but usually only for a few minutes, and often for recreation. Dare Win is the first group to freedive with them with the sole intention of collecting data.

Schnoller's methods are considered reckless by many marine mammal researchers. Sperm whales can be dangerous - they are the largest toothed predators on earth. They can weigh up to 100,000lb (45 tonnes) and grow up to 60ft (18m) in length. They have a row of eight-inch-long (20cm) teeth which they use to hunt giant squid at depths of 9,000ft (1.7 miles, 2.7km).

A sperm whale could swallow a human — a few humans — within a matter of seconds, without ever pausing to chew. According to historical records, they did that often. Whaling ship logs from the 18th and 19th Centuries are filled with accounts of vicious attacks on sailing boats, rowing boats and swimmers.

Image copyright Thinkstock

Paintings from that era depict scenes of enormous sperm whales causing mass destruction if anyone was foolish enough to hunt them.

Herman Melville's classic novel Moby Dick was based on a real sperm whale attack that destroyed the Essex whaling ship in 1820. Of the 21 crew members aboard the Essex, just eight survived and were rescued after more than 80 days at sea.

But the Dare Win team convinced me that many of the old logs and paintings were most likely exaggerations or in some cases outright fabrications.

Sperm whales, they said, don't want to eat humans - they only attack when they are attacked, and then only do so rarely. The old myths have been perpetuated because so few people have studied the animals.

Nonetheless, while swimming side-by-side with them, sperm whales can accidentally smother you, decapitate you with their tails, and many researchers believe they can also vibrate your body to death with their most intense vocalisations if they choose - they are the loudest animals on the planet.

These vocalisations form part of their echolocation system - they send out a click from the front of their noses then listen for the echoes that resonate in a fatty sac beneath their mouths.

It's the most precise and powerful form of biosonar ever discovered. They can detect a 10-inch-long squid from 1,000 feet (300m) away and a human from more than a mile (1.6km) away.

Image copyright Frederic Buyle

The clicks are so powerful they can penetrate flesh and allow whales to see not only where objects are, but what they look like from the inside out. In essence, sperm whales have X-ray vision.

Getting "scanned" in this way is not only incredibly loud, it can also be incredibly painful. One Dare Win researcher told me how he was diving with sperm whales a year ago and attempted to push a calf away from his camera. The calf's nose was vibrating so violently from the clicks that it paralysed the researcher's hand for four hours.

A different type of vocalisation, using what are known as coda clicks, is also used to communicate with other sperm whales and can be heard hundreds of miles away.

Dare Win researchers have recorded dozens of hours of these noises which they and a team of researchers from the University of Paris are now studying. They believe the coda clicks form a sophisticated language. Sperm whales have the largest brain ever identified, about five times larger than the human brain.

Sperm whales

Image copyright Frederic Buyle

The name comes from the word spermaceti - the waxy oil found in sperm whales' heads

Whalers would extract the spermaceti which was then used to make ointments, creams, candles and industrial lubricants

Sperm Whales are on the International Union for Conservation of Nature's list of vulnerable species

There are an estimated 360,000 sperm whales alive today - they are found in every ocean but not the polar ice fields

Pods tend to consist of up to 15 mature females and their offspring - males live much of their lives alone or in smaller groups

Sources: Encyclopaedia Britannica and Natural History Museum

As we swim beneath the surface of the Indian Ocean, the mother and her calf approach head-on but then, 30ft (9m) before colliding with us, start to veer away pulling softly to the side. The calf bobs its head slightly, staring with an unblinking eye. Its mouth turned up at the end, like it is smiling. The mother wears the same expression, as all sperm whales do.

The rhythm of the clicks shifts - it seems that the echolocation clicks have become coda clicks. The whales are identifying themselves to us, they are, perhaps, trying to make contact.

They keep their gaze upon us as they pass within a dozen feet of our faces, softly shower us with clicks, and retreat slowly back into the shadows. The coda clicks turn back to echolocation clicks, then the echolocation fades, and the ocean, once again, falls silent.

Image copyright Yann Oulia Image caption Dare Win researcher swimming with a humpback whale

James Nestor is the author of Deep: Freediving, Renegade Science, and What the Ocean Tells Us about Ourselves

He spoke to Outlook on the BBC World Service. Listen again on iPlayer or get the Outlook podcast.

Subscribe to the BBC News Magazine's email newsletter to get articles sent to your inbox.