Learn / updated 2026-10-05
How CNPJ numbers work: format, check digits and what a lookup returns
The CNPJ (Cadastro Nacional da Pessoa Jurídica) is the 14-digit registration number of a legal entity in Brazil, issued by the Receita Federal. Supplier checks, invoices and onboarding forms all ask for it.
The structure
A CNPJ is written XX.XXX.XXX/YYYY-ZZ:
- Eight digits identify the company (the base).
- Four digits after the slash identify the establishment:
0001is the head office,0002and up are branches. - Two check digits at the end.
Dots, slash and dash are formatting only. 33.000.167/0001-01 and 33000167000101 are the same number.
How the check digits are calculated
Both check digits use modulo 11:
- Take the first 12 digits and multiply them by the weights
5 4 3 2 9 8 7 6 5 4 3 2, then add the products. - Take the remainder of the sum divided by 11. If it is below 2 the first check digit is 0, otherwise it is 11 minus the remainder.
- Repeat with the first 13 digits (the 12 plus the first check digit) and the weights
6 5 4 3 2 9 8 7 6 5 4 3 2.
Numbers where all 14 digits are the same (11111111111111) pass the arithmetic but are not valid and are rejected.
function validCnpj(d) {
if (!/^\d{14}$/.test(d) || /^(\d)\1{13}$/.test(d)) return false;
const dv = n => { let s = 0, w = n - 7; for (let i = 0; i < n; i++) { s += +d[i] * w--; if (w < 2) w = 9; } const r = s % 11; return r < 2 ? 0 : 11 - r; };
return dv(12) === +d[12] && dv(13) === +d[13];
}
This catches typos at the form. It does not tell you that the company exists: a number can have correct check digits and never have been issued.
What a registry lookup adds
A lookup against the Receita Federal open data answers the questions the arithmetic cannot: is there a registration for this number, what is the legal name, is it active, suspended or closed, when did it start, where is it, and which activity code (CNAE) does it carry.
What it should not return is information about people. Individual entrepreneurs (MEI) are registered under a person's name, and the public data includes partner lists, phone numbers and e-mail addresses. A company-level lookup leaves those out.
Try it
The CNPJ lookup validates the check digits first and then returns the company record with a link to its source. It is also available as a free MCP tool, a pay-per-call x402 endpoint and an Apify Actor for batches.
This is general information, not legal or tax advice, and a lookup does not replace an official extract.
Related
- Brazil CNPJ Checker: API reference
- CPV codes and OCDS explained: how public tenders are described
- How EU VAT number validation works (VIES explained)
- How PDF to Markdown conversion works: text layer, layout and OCR
- SPF, DKIM and DMARC explained: how e-mail authentication works
- All tools and prices
Informational only, not financial, legal or tax advice.