Brazil CNPJ Validator

Verify Brazilian company ID numbers with the real two-step mod-11 algorithm.

Ad placeholder (leaderboard)
Enjoying the tools? Go Pro for £4.99 (one-time) and remove all ads — forever, on this device. Remove ads — £4.99

The CNPJ (Cadastro Nacional da Pessoa Jurídica — National Registry of Legal Entities) is the 14-digit taxpayer identification number issued by the Brazilian Federal Revenue Service (Receita Federal) to every company, association, public body, and self-employed professional registered in Brazil. You encounter it on invoices, contracts, and government forms whenever you deal with a Brazilian legal entity. Unlike a simple sequential identifier, a CNPJ encodes structure: the first eight digits identify the company root, the next four digits identify the specific branch or establishment (with “0001” always meaning the head office), and the final two digits are check digits calculated by a well-defined two-step algorithm.

This validator recomputes both check digits from scratch, shows the weighted sums and modular remainders so you can follow the arithmetic, identifies whether the branch is a head office or subsidiary, and rejects the class of all-identical strings that would otherwise pass the maths by coincidence.

How the algorithm works

The CNPJ uses a weighted mod-11 scheme — the same family of algorithms used by many national ID systems — but with a specific weight cycle chosen by Receita Federal. The calculation proceeds in two independent passes.

Pass 1 — computing the 13th digit:

Take the first 12 digits of the CNPJ. Multiply each by its weight from the sequence [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2] and sum the products. Divide by 11 and keep only the remainder. If the remainder is 0 or 1 the check digit is 0; otherwise it is 11 − remainder.

Pass 2 — computing the 14th digit:

Take the same 12 base digits, append the first check digit just computed (giving 13 digits), and repeat with a shifted weight sequence: [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]. Apply the same sum → mod 11 → (rem < 2 ? 0 : 11 − rem) formula to get the second check digit.

The CNPJ is valid if and only if both computed digits match the two digits printed at positions 13 and 14, and the number is not an all-identical string.

Worked example

Using the obviously-fake number 11.222.333/0001-81:

  • Base (12 digits): 1 1 2 2 2 3 3 3 0 0 0 1
  • Weights (pass 1): 5 4 3 2 9 8 7 6 5 4 3 2
  • Weighted products: 5 + 4 + 6 + 4 + 18 + 24 + 21 + 18 + 0 + 0 + 0 + 2 = 102
  • 102 mod 11 = 3 → check digit 1 = 11 − 3 = 8
  • Pass-2 input: 1122233300018 (13 digits, appended the 8)
  • Weights (pass 2): 6 5 4 3 2 9 8 7 6 5 4 3 2
  • Sum = 6+5+8+6+4+27+24+21+0+0+0+3+16 = 120
  • 120 mod 11 = 10 → check digit 2 = 11 − 10 = 1
  • Both match the printed -81Valid CNPJ
CNPJVerdict
11.222.333/0001-81Valid
11.222.333/0001-80Invalid — 2nd check digit wrong
11.222.333/0002-81Invalid — both digits wrong
11111111111111Invalid — all-identical sequence

Every calculation runs entirely in your browser. No data is transmitted or stored.

Ad placeholder (rectangle)