BORME API

Engineering notes · Data quality

The check character is not input validation: it is a measuring instrument

2026-08-25 · 5 min · field note

By BORMEAPI Engineering

A lookup came in for the tax ID B42413283. We answered, truthfully as far as it went:

We hold no company under this NIF. BORME has no dedicated tax-ID field, so the mapping is cross-referenced from open sources and covers a minority of the companies we hold.

Every clause of that is accurate and the whole thing is a lie by omission. B42413283 fails the check-character rule our API applies. That almost always indicates a typo, so check the number against the original document before trying another data provider. You can reproduce the check with a pocket calculator.

The last character is not data

Order EHA/451/2008 sets the structure of a Spanish company's NIF: a letter, seven digits and a control character. Neither the order nor Royal Decree 1065/2007 gives the arithmetic for that last character. The rule our API applies, which reproduces the NIFs that public bodies publish for themselves, works on the seven digits. Double the digits in odd positions and add their digits together, add the digits in even positions; the control value is what the sum needs to reach a multiple of ten, or 0 if it already is one. For a NIF beginning with B, that value is written as a digit:

B 4 2 4 1 3 2 8 ?
  ↑   ↑   ↑   ↑     doubled: 8, 8, 6, 16→7   = 29
    ↑   ↑   ↑       as-is:   2 + 1 + 2       =  5
                                        total = 34
                          check digit = 10 − 4 = 6

For the body we received, the rule gives B42413286; the identifier we were handed ends in 3. One character out of nine carries no information of its own: it is redundancy that helps catch transcription errors, though it cannot say which character was mistyped.

Which entities get a digit and which get a letter is its own small thicket: A, B, E and H take the digit; N, P, Q, R, S and W take a letter off JABCDEFGHI; C, D, F, G, J, U and V accept either. Personal IDs are a different algorithm entirely - DNI is eight digits mod 23 against TRWAGMYFPDXBNJZSQVHLCKE, and a NIE is the same with X, Y, Z read as 0, 1, 2. K, L and M we decline to judge, because the rules for them have moved and a wrong "invalid" is worse than an honest "unknown".

Validate at the boundary. Never refuse before you look.

The tempting move is to reject a bad check character at the door. We deliberately do not, and the reason is that we hold data harvested from sources that are themselves imperfect. If a mapping in our table has a broken check character, refusing to look it up means refusing to return a row we actually have - a false negative introduced by validation, which is the worst kind.

So the arithmetic runs only after the query misses. A hit is returned no matter what its check character says. A miss gets the honest reason:

{
  "error": "nif_check_character_failed",
  "nif": "B42413283",
  "format_valid": true,
  "check_character_valid": false,
  "corrected_check_character": "B42413286",
  "note": "…for B4241328 it is 6, not 3. This is almost always a typo - check
           the number against the original document."
}

Zero false negatives, and a caller who now knows to check their own invoice rather than shop for a better data provider.

Then we pointed it at ourselves

That is the boring half. The interesting half is what happens when you run the same arithmetic over your own table.

We hold 527,318 NIF→company mappings, cross-referenced from eighteen sources, because BORME itself has no dedicated tax-ID field. Nineteen of them fail their own check character. That is 0.0036%, which sounds like a rounding error until you ask where the nineteen are:

Kind of sourceMappingsFailingRate
Official structured registers and catalogues432,86000%
Public procurement portals91,43640.004%
Companies' own aviso legal pages78010.128%
Our own parser over BORME free text2,242140.624%

Every structured official register and catalogue is perfectly clean across 432,860 mappings, including those from GLEIF, BDNS and AEAT. Not "clean enough". Zero.

And the one source that reads a tax ID out of prose rather than out of a key column carries 14 of the 19 failures, at 173× the overall rate.

That is not a surprise so much as a confirmation with a number attached. When a register stores a NIF, it stores it as an identifier: something validated it on the way in, and it has been a primary key ever since. When our own parser digs a NIF out of a sentence in the gazette (a sentence that has been through typesetting, PDF generation and our extraction regex), nothing between the notary and us ever checked the arithmetic. The check character is the only place that corruption becomes visible.

Three of the four procurement-portal failures are a different problem altogether. B0011479C sits on MOOG SARL, B0041480E on RÖSLER INTERNATIONAL GMBH & CO KG, W48083521 on QBE EUROPE SA/NV. Those are not corrupted Spanish tax IDs - they are foreign identifiers written into a field labelled NIF, by a supplier who had no Spanish one to put there. The arithmetic cannot tell you that, but it can tell you where to look.

The trap in "did you mean"

The obvious next feature is suggestions, and it is a better feature than it first appears. Under the CIF algorithm each body position admits exactly one replacement digit that closes the arithmetic, so a nine-character identifier has precisely eight single-character corrections - a short list, not a search space. B42413283 gives you B42413286 plus seven others.

Then we checked those candidates against the table, and the data argued back. Of the nineteen broken mappings we hold, not one had its check-character fix in our table. Three had an unrelated one-digit neighbour. BROS MAQUINARIA SL had three neighbours at once (CERTIS CORP SL, NARANJAS DEL SURESTE SL and SOFTWARE MAQUINARIA Y MANTENIMIENTO SL), and no reading of those names makes any of them the same company.

The arithmetic is doing exactly what you would expect it to. We hold on the order of half a million identifiers; a prefix admits ten million. A candidate one digit away therefore lands on some real company perhaps one time in twenty, purely by coincidence, and offering seven of them gives coincidence seven chances. So suggestions ship with their provenance attached: the check-character fix is offered plainly, and a one-digit neighbour is labelled as one and carries a warning that it is as likely to be a stranger as your company.

A checksum is normally filed under input validation, which undersells it. It is the only instrument that can audit an identifier with no second source to compare against - which makes it the cheapest data-quality measurement you own, and the only one that works on the data you have already stored.

If you cross-reference identifiers from more than one source, run the arithmetic over your whole table once. Ours took under a minute and named the weak source without an argument.

Updated 25 October 2026. The figures in this post, including the eighteen sources in the title, describe our table in August 2026. Today it holds more than 580,000 NIF mappings, from more than twenty sources. The check-character counts above are from the August run.

Updated 24 October 2026. The link to Order EHA/451/2008 pointed to the wrong document in the BOE, an unrelated order; it now points to the order itself (BOE-A-2008-3580). The post also said that the order defines how the check character is computed. It does not: it sets the structure of the NIF of companies and other entities, and the arithmetic is the rule our API applies. That paragraph now says so.

Updated 12 October 2026. The quote at the top of this post is an excerpt from the 404 message the API returns for an unmapped NIF. Its second sentence, and our own sentence introducing the source table, used to say that BORME carried no tax IDs at all. The last row of that table shows why that was too strong: some notices do print a company's NIF in their text, and that text is one of our sources. The message, the quote and that sentence now say that BORME has no dedicated tax-ID field.

API docs Pricing & tiers

build 2026.11.26·74cb804a