A young Stephen Fry is sitting on a couch, philosophising about the English language. He’s sporting an unfashionable pageboy haircut and has the air of a serious academic.

He’s talking about the infinite ways words can be combined. He gestures emphatically as he explains “Hold the newsreader’s nose squarely, waiter, or friendly milk will countermand my trousers.”

He pauses to let his point sink in, then continues “One sentence, common words, but never before placed in that order… You see?”

Hugh Laurie looks at the camera, opens his mouth as if to explain, then decides against it.

The famous Fry & Laurie language sketch parodies the lofty pontificating of academics – which often borders on the nonsense. But the comedy duo inadvertently hit upon an ancient linguistic discussion.

“One of the really striking things about human language is that we are able to talk about things that we’ve never talked about before,” says Simon Kirby, who studies the origins of language at the University of Edinburgh.

Old words, new ideas

Take English. Most native speakers know around 30,000 words. That’s not many when you consider the average person may utter 20,000 in just one day. Everything you want to say in your lifetime – around 1.9 trillion thoughts on average – must be expressed using this modest internal dictionary.

No other animals – except oddly, budgies – have been observed putting strings of sounds together to innovate new meanings

And every time you open your mouth, there’s the possibility you’ll say something which has never been said before. Something like “Due to overwhelming reader response, I have added breasts to the space dinosaur cowboy” – which, incidentally, is a real sentence from the internet. We’re the only species which can do this. That’s because, though the animal kingdom is replete with squeaks, growls, whimpers, grunts and yelps, no other animals – except oddly, budgies – have been observed putting strings of sounds together to innovate new meanings.

“It’s a really, really blindingly obvious part of language – you have words and they have small meanings and you put them together and they have bigger meanings – but we don’t see this anywhere else in nature,” says Kirby. To understand how we do that, you have to create words and sentences that are even more nonsensical than Fry and Laurie’s sketch.

In fact, in every corner of the globe, from the nomadic Yupik people of Siberia to the remote uncontacted Kawahiva tribe of the Amazon, human languages are extremely logical. Despite thousands of years of modification by migration, invasion and trade, all human languages have emerged with a common set of rules.

But many people are never explicitly taught this logic – and no one has ever sat down to design a language. How do we learn these rules? And where did they come from in the first place?

For centuries, the seemingly magical way we learn thousands of words and some highly complex grammar by the age of five remained a mystery. Then psychologist Jean Gleason at Boston University struck upon an ingenious idea. 

“If you want to know if children know that the plural of dog is dogs, you could ask. But you won’t know if they have just memorised ‘dogs’,” she says. To gain a window to their unconscious understanding, she realised she’d have to expose them to words they’d never heard before. She’d have to make some up.

Back in the 1960s, that’s exactly what she did. With colleagues from Boston University, Gleason looked at children’s books to figure out which rules children might feasibly know. Next they invented some nonsense words and Gleason sat down and imagined up the pictures to go with them.

Then she put children to the test.  “There would be a picture of a man doing some weird thing and you’d say ‘This is a man who knows how to zib. What is he doing? He is…’ what would you fill in?” He’s zibbing. “That’s right.” Zibbing is, of course, when you balance a ball on your nose.

She was looking for their intuitive ability to add the right endings to words, such as adding an “s” to plurals. The classic was The Wug Test, after which the technique was named. “This is a wug. Now there are two of them. There are two…” Though they had never heard the word before, children who understood the rules said “wugs”.

The children were asked about a whole menagerie of strange creatures, including wugs, luns, tors, heafs, cras, tasses, gutches, kazhes and nizzes and eccentric men who binged, glinged, ricked, spowed, motted, bodded and zibbed. The children took their task very seriously; sometimes they’d say "That’s a hard one” and ponder for a while before answering, or answer and then hastily correct themselves.

So what is a wug? “Oooh! Well they’re really cute. They’re blue with little feet and they look rather like a little wingless bird,” says Gleason.

Decades after his comedy sketch, Stephen Fry visited Gleason in Boston for a documentary series about language. “We went down to the local school and sat down with the children and did the test. They weren’t very cooperative that day but he was a lot of fun,” she says.

To Gleason’s surprise, even very young children – around three years old – already had a firm grip on grammar. They could easily tell her that a man had “spowed” the day before or that they were, in fact, looking at two “wugs”. 

The tricky ones were those which already had these “s” or “d’ endings, such as the past tense of “bod”, which they didn’t learn to express by saying ‘bodded’ until much later. In Gleason’s made-up world, bodding is the practice of dangling an object on a string.

“It wasn’t that children learned these rules in different interesting ways; they basically all learnt the most common, simple cases first,” says Gleason. Regardless of intelligence, economic background or parenting, they all learnt the same skills at the same ages, in the same order, in the same way.

Today The Wug Test has been translated into numerous other languages, copied hundreds of times and is widely renowned as a classic. Intriguingly the same patterns – such as learning plurals first – are repeated in other languages too, such as Gleason’s native Hungarian. “Children learn to speak in a very, very regular way,” she says.

Alien languages

But where do the rules of the languages themselves come from? Why is it that English usually adds an “s” to make a plural or an “ed” to talk about the past? Grammatical rules vary so widely between languages, the particular details cannot be hardwired in our genes, yet we clearly pick them up very quickly.

Some clues come from another nonsense experiment, by Kirby and a team of scientists from the University of Edinburgh. “There are these two unique things about language: this unique structure which allows us to talk about things we’re never talked about before and that we learn it from our parents,” he says. They had a hunch that the two might be related.

To study how languages acquire their logic, they could have looked to any language on the planet – since they all have these features – but they are all big, complicated and take years to learn. The scientists needed something simpler. So they decided to make one up.

 “We call it an alien language, mainly because it sounds exciting so gets people to sign up for our experiments,” says Kirby. They used computers to generate random strings of syllables and assigned a meaning to each new word. In one version, the words described exotic fruits the team had invented.

 “There was nothing there – it wasn’t even a language, really. It was just a complete soup of words with these complex meanings,” says Kirby.

Next they recruited a group of students willing to study a language of no use whatsoever. They were taught by a computer program and later tested on their knowledge. “We’d show them objects in the world and say what will the alien call this?”

But there was a twist. The team also snuck in objects which the participants hadn’t been trained on and asked them what they were called. “They usually don’t notice because it’s really quite a big, complicated task,” says Kirby. Without realising what they were doing, the volunteers would simply make the word up.

The words shown to the first participant – including the new ones – became the language used to train the second participant. The words from the second generation were shown to the third, the third to the fourth, and so on.

It’s like a game of Chinese whispers where children whisper into the ear of the person sitting next to them and the sentence changes as it goes from person to person. The alien language evolved as it was passed from one generation to the next – gradually transforming from nonsense into something which resembled a real-world language.

After just six generations, the alien language had a kind of logic

Gradually, structure began to emerge and the language developed rules similar to those in real languages. After just six generations, the language had a kind of logic called compositionality.

“It sounds complicated but it’s actually very, very simple and obvious – it’s the fact that you can work out the meaning of the sentence if you know the meaning of all the words in a sentence and some basic rules of how they are put together,” says Kirby.

He uses the example of “cyan pentagon”, which immediately conjures up an image of a cyan-coloured, pentagon-shaped object, though that combination of words may never have been used before in all the written product of the English language through history.

To begin with, every object in Kirby’s experiments was described using a unique string of syllables. By the end, the words had been divided into subparts with meanings which could be combined. Flower-shaped fruits were described by words beginning with “mega”, while a check pattern was described by the ending “wawa”. So a flower-shaped fruit with a check pattern came to be known as a “mega-wawa”.

“It’s this process of cultural transmission which gives human languages their unique structure,” says Kirby. The meanings have to fit to survive being passed from one generation to the next. 

The ability to combine words is so powerful and so automatic, it’s no wonder that – from Lewis Carroll’s slithy toves (a combination of slimy and lithe) to Roald Dahl’s scrumdiddlyumptious (a combination of diddly and scrumptious) – the delectably weird words of nonsense literature can be as evocative as any in the English language.  

So there you have it. When someone says something nonsensical – such as “Hold the newsreader’s nose squarely, waiter, or friendly milk will countermand my trousers” – it may sound random, but it is still following a logic that was crafted over hundreds of generations and tens of thousands of years.

 Join 700,000+ Future fans by liking us on Facebook, or follow us on Twitter, Google+, LinkedIn and Instagram.

If you liked this story, sign up for the weekly bbc.com features newsletter, called “If You Only Read 6 Things This Week”. A handpicked selection of stories from BBC Future, Earth, Culture, Capital, Travel and Autos, delivered to your inbox every Friday.