Image copyright iStock

On a ramshackle pig farm near Wuxi, in Jiangsu province, China, a foreigner gets out of a taxi.

The family are surprised. Their little farm is at the end of a bumpy track through rice paddies, and they do not get many foreigners asking to use the toilet.

The stranger's name is Philip Lymbery, and he runs a campaigning group called Compassion in World Farming.

As he explains in his book about intensive farming, he is not there to berate the farmers about their pigs' living conditions, although sows are crammed uncomfortably into crates.

Mr Lymbery is there to investigate whether pig manure is polluting the local waterways.

He has tried unsuccessfully to visit local large, commercial farms, so has turned up on spec at a family farm instead.

The farmer is happy to talk.

Yes, they dump waste in the river. No, they are not supposed to. But they just bribe the local official.

Then, Mr Lymbery notices a pile of needles for antibiotics. Have they been prescribed by a vet? No, the farmer explains. You don't need a prescription to buy antibiotics.

And anyway, vets are expensive. Antibiotics are cheap. The farmer has very little money, so she injects her pigs with them routinely, hoping it will stop them getting sick.

Find out more

50 Things That Made the Modern Economy highlights the inventions, ideas and innovations that helped create the economic world.

It is broadcast on the BBC World Service. You can find more information about the programme's sources and listen online or subscribe to the programme podcast.

She is far from alone. Cramped and dirty conditions on intensive farms are breeding grounds for disease. Routine, low antibiotic doses can help to stop it spreading.

Antibiotics also fatten animals, which means more money for farmers. Scientists are studying gut microbes to understand why.

No wonder more antibiotics are injected into healthy animals than sick humans.

In the big emerging economies - where demand for meat grows as incomes rise - use of agricultural antibiotics is set to double in 20 years.

Widespread unnecessary use of antibiotics is not restricted to agriculture.

Many doctors are guilty, too.

They should know better - as should regulators who let people buy antibiotics over the counter.

Serendipity

Meanwhile, bacteria are busily evolving resistance to drugs, and public health experts fear we are entering a post-antibiotic age.

One recent review estimated drug-resistant bugs could kill 10 million people a year by 2050 - more than currently die from cancer.

It is hard to put a monetary cost on antibiotics becoming useless, but the review tried: $1tn (£790bn).

The story of antibiotics starts with a healthy dose of serendipity.

A young man named Alexander Fleming had a boring job in shipping when his uncle died, leaving him enough money to resign and enrol at St Mary's Hospital Medical School in London instead.

Image copyright Getty Images Image caption Sir Alexander Fleming was jointly awarded the Nobel Prize for medicine in 1945 for his work on penicillin

There, he became a valued member of the rifle club.

The captain of the shooting team wanted to keep Fleming when his studies finished, so found him a job.

That is how Fleming became a bacteriologist.

One day in 1928, Fleming failed to tidy up his petri dishes before going back home to Scotland on holiday.

On his return, he noticed one dish had become mouldy in his absence, and the mould was killing the bacteria he had used the dish to cultivate.

Fleming tried to investigate further by making more mould, but he was not a chemist and could not work out how to make enough.

He published his observations, but nobody paid attention.

A decade passed, then more serendipity.

In Oxford, Ernst Chain was flicking through back copies of medical journals when he chanced upon Fleming's old article.

And Chain, a Jew who had fled Nazi Germany, was a chemist - a brilliant one.

Chain and his colleague Howard Florey set about isolating and purifying enough penicillin for further experiments.

This required hundreds of litres of mouldy fluid.

Their colleague Norman Heatley rigged up a crazy-looking Heath Robinson system involving milk churns, baths, ceramic bedpans commissioned from a local pottery company, rubber tubes, drinks bottles and a doorbell.

They employed six women to operate it - the "penicillin girls".

Image copyright Alamy Image caption Women working in Distillers penicillin laboratory in Liverpool, in March 1946

The first patient given an experimental dose was a 43-year-old policeman who had scratched his cheek pruning roses and developed septicaemia.

Heatley's makeshift system could not produce penicillin quickly enough, and the policeman died.

But, by 1945, penicillin - the first mass-produced antibiotic - was rolling off production lines.

Chain, Florey and Fleming shared a Nobel Prize.

And Fleming took the opportunity to issue a warning.

The tragedy of the commons

"It is not difficult," Fleming said, "to make microbes resistant to penicillin in the laboratory by exposing them to concentrations not sufficient to kill them."

Fleming worried an "ignorant man" might under-dose himself, allowing drug-resistant bacteria to evolve.

But ignorance hasn't been the problem.

We know the risks, but face incentives to take them anyway.

Image copyright SPL Image caption The first case of an infection that can resist the antibiotic of last resort has been detected in the US

Suppose I feel ill.

Perhaps it is viral, meaning antibiotics are useless. Even if it is bacterial, I will probably fight it off.

But if there is any chance that antibiotics might speed my recovery, my incentive is to take them.

Or suppose I run a pig farm.

Giving routine low doses of antibiotics to my pigs is the perfect way to breed antibiotic-resistant bacteria.

But that is not my problem.

Image copyright iStock

My only incentive is to care about whether dosing my pigs seems to increase my revenues by more than the cost of the drugs.

This is a classic example of the tragedy of the commons, where individuals rationally pursuing their own interests ultimately create a collective disaster.

Until the 1970s, scientists kept discovering new antibiotics: when bacteria evolved resistance to one type, we could introduce another.

But then the development pipeline dried up.

It is possible new antibiotics will start coming through again.

Some researchers have come up with a promising new technique to find antimicrobial compounds in soil.

More from Tim Harford

How the barcode changed retailing

The warrior monks who invented banking

Why the falling cost of light matters

How Ikea's Billy bookcase took over the world

Again, though, this is all about incentives.

What the world really needs is new antibiotics we put on the shelf and use only in the direst emergencies.

But a product that does not get used is not much of a money spinner for drug companies.

We need to devise better incentives to encourage more research.

One attempt to do just that is called an "advanced market commitment", where donors promise to pay for doses of a medicine that does not yet exist.

We will also need smarter regulations as to how new antibiotics are used, by doctors and farmers alike.

Denmark shows it can be done - world-famous for its bacon, it strictly controls antibiotic use in pigs.

One key appears to be improving other regulations to make farm animals' living conditions less cramped and unhygienic.

That makes disease less likely to spread.

And recent studies suggest that when animals are kept in better conditions, routine low doses of antibiotics have very little impact on their growth.

The pig farmer in Wuxi meant well.

She clearly did not understand the implications of overusing antibiotics.

But even if she had, she would have faced the same economic incentives to overuse them.

Ultimately, that is what needs to change.

Tim Harford writes the Financial Times's Undercover Economist column. 50 Things That Made the Modern Economy is broadcast on the BBC World Service. You can find more information about the programme's sources and listen online or subscribe to the programme podcast.