It was one of the more surprising features of the Budget, a Digital Services Tax designed to make tech giants earning vast revenues in the UK pay their fair share.

Now comes the difficult part - working out how the tax will be designed and who will pay it.

The tax looks as though it is targeted at the likes of Google, Amazon and Facebook - the Treasury says it will apply to search engines, online marketplaces and social media firms.

"You can't specify the named firms so you think what characteristics catch them but not start-ups," says Jill Rutter, a former Treasury civil servant who now works for the Institute of Government.

She says the chancellor will have had two worries in designing the tax - "catching things he doesn't want to catch - or not catching what he does want to catch."

But tax lawyer Dan Neidle from Clifford Chance says there is a guiding principle behind the tax. "The highfalutin theory is that value is being created by users for these companies and not being taxed. So for instance, you put a picture of a cat on Facebook, people click on an advert next to it and Facebook earns money from that."

Social media firms and search engines will pay the 2% tax on the advertising revenue earned from UK users in this way. When it comes to online marketplaces, the aim is not to put a tax on the payment from the consumer but on the "platform fee", the commission paid by the merchants using the market.

Firms will only pay the tax if they have global revenues of at least £500m. They have to be profitable, and the first £25m of UK revenues will be tax free. The Office for Budget Responsibility says around 30 companies could end up being affected. So let's look at who might fit into each category:

Search engines: It's hard to see any business other than Google and Microsoft's Bing qualifying for the tax

Social Media firms: Facebook certainly fits the bill, and don't forget it also owns Instagram which is now generating lots of advertising revenue. But what about the UK's other favourite social hangouts Twitter and Snapchat? They aren't making profits - until they do they're exempt.

Online Marketplaces: Here it gets a lot more complex. Ebay certainly qualifies but tax experts are divided about Amazon, It won't pay anything on revenues earned from direct sales to shoppers but what about the commission from merchants using the Amazon Marketplace as a platform to sell their wares?

Food Delivery: Then there is speculation about a couple of UK firms in the food delivery business, Deliveroo and Just Eat. Their business model - earning commission from restaurants dependent on their platform - appears to qualify but Deliveroo's revenues are below the threshold and neither company is making a profit. But that could change by 2020 when the tax comes in.

So for now it seems that only American tech firms could qualify. "Very few British firms are big enough - this is aimed at US giants and that brings a risk," says Heather Self at the accountants Blick Rothenberg. She warns that if the Trump administration sees this tax as effectively a tariff on successful American businesses that could end up with a complaint to the World Trade Organization.

What is clear is that there is a lot of painful work ahead on a tax which, in the words of Heather Self, will raise a lot less than the chancellor earmarked for mending potholes.

Jill Rutter from the Institute of Government says even the £400m projected return is "the most uncertain figure in the Budget", though she suspects Facebook is one firm that will pay up without making a fuss: "2% is a drop in the ocean for them. Nick Clegg (Facebook's new communications supremo) may advise them it's not worth the reputational risk to argue about it."

If the tax was about assuaging public anger about the low tax paid by giant firms, it may not do the job - after all the world's wealthiest business, Apple, and Uber, one of the most controversial, both seem unlikely to be affected,.

"The problem with sector-specific taxes is you create lots of uncertainty - and lots of work for people like me," says Dan Neidle. So at least the tax lawyers will be happy.