Image copyright Getty Images Image caption Barclays has been told to pay back avoided tax

All Britain's big banks have signed a code committing them not to engage in tax avoidance.

So it is highly embarrassing for Barclays that it has been accused by Her Majesty's Revenue and Customs of designing and using two schemes designed to avoid substantial amounts of tax.

The government yesterday closed two tax avoidance schemes, to retrieve £500m of lost tax and safeguard payments of billions of pounds more tax in the future.

One of the outlawed schemes was a way of avoiding tax payments when a bank buys back its own debt. David Gauke, Exchequer Secretary to the Treasury, described this scheme as a transaction that a bank which has adopted the anti-tax-avoidance code "should never have adopted."

The other outlawed scheme, exploiting provisions of regulations on Authorised Investment Funds, seeks to generate tax credits when tax has not been paid in the first place.

The measure taken to ensure tax is paid on debt repurchases or buybacks is highly unusual in having retrospective effect: it claws back tax already saved.

Barclays has not been named officially by the government, but the BBC has been told by several well placed sources that it is the target of HMRC's crackdown.

The BBC has approached Barclays for comment but there has been no response to calls and text messages.

UPDATE 08:00

In November, Bob Diamond, the chief executive of Barclays, gave the inaugural Today Lecture, in which he argued that banks can and must be "good citizens".

And just over a couple of weeks ago, when Barclays announced its 2011 annual profits, the first page of its results announcements was not the normal list of putative financial achievements. It was in fact headed "Citizenship - performance highlights" (I highlighted this intriguing innovation in my note that day).

Among the citizenship milestones that it flagged up was that its activities generate a good deal of tax for governments around the world - although as I pointed out at the time, many people regard paying tax as just one of those things we all have to do, rather than an achievement beyond the call of duty and worthy of particular mention.

As it happens, the numbers it highlighted for its tax payments weren't particularly easy to understand. It said that in 2011 it "paid total tax globally (directly and indirectly) of £6.4bn, including £2.9bn in the UK". But later on in the results, Barclays said its total corporation tax payments were actually £1.7bn. So what were the other £4.7bn of taxes that it says it paid?

Barclays' charge for tax in its profit and loss account, as opposed to the corporation tax that it actually paid, was a bit higher, at £1.9bn - but still a long way from that £6.4bn (or even the £2.9bn it says in paid in the UK).

Anyway, and at the risk of stating the bloomin' obvious, the reason HMRC's crackdown on two tax avoidance schemes designed and used by Barclays is so embarrassing for the big bank is precisely because Barclays has made the connection in public between citizenship and paying taxes.

Media playback is unsupported on your device Media caption David Gauke: We are willing to step in and act

Also, the way that the Treasury minister David Gauke described the schemes was not exactly flattering to Barclays - describing one as in breach of the Code of Practice against tax avoidance that Barclays signed, and the other as contrary to the taxing intentions of parliament and the spirit of the law.

As I said last night, I asked Barclays for a comment on all this. And so far it has said nothing to me.

What the owners of Barclays will presumably want to hear from Mr Diamond is whether he was aware of the two tax avoidance schemes and if so how he squares those schemes with the ethos he is trying to foster in his organisation.

PS: Was it only me who found it intriguing that the Treasury was bashing up Barclays over tax avoidance within hours of the eviction of the putatively anti-bank movement Occupy from outside St Pauls?

UPDATE 08:07

I have now spoken to Barclays, and it says that it is a bit surprised that HMRC reacted as strongly as it did to the two tax avoidance schemes.

These were, it believes, in line with tax schemes used by other banks.

And it says that, because it signed up to the anti-avoidance code, it ran the schemes past HMRC.

Barclays also points out that the schemes were by definition legal, because the government is having to rewrite the rules to make them illegal.

As for its liability, it does not believe that all the clawed back tax of £500m will come from it - which implies that other banks were using the debt buyback device to avoid corporation tax.

What will be the hit for Barclays? It won't say. But I am hearing that Barclays may end up paying no more than £150m of additional tax.