Brazil CPF & CNPJ Generator and Validator (Testing Tool)
Generate and validate Brazilian CPF and CNPJ document numbers with optional formatting punctuation, state origins, and bulk export for software testing.
About Brazil CPF & CNPJ Generator and Validator (Testing Tool)
Developing and testing business software in Brazil requires validating two foundational taxpayer identification numbers: the CPF (Cadastro de Pessoas Físicas) for individuals and the CNPJ (Cadastro Nacional da Pessoa Jurídica) for commercial enterprises.
Database validations, e-commerce checkout funnels, and enterprise ERP systems enforce strict mathematical checksums on these numbers using the Modulo 11 check digit algorithm. Using arbitrary placeholder digits like 123456789 causes automated test suites to fail validation gates.
This Brazilian CPF and CNPJ Generator and Validator produces mathematically valid test numbers adhering to official Receita Federal formatting rules. It supports optional punctuation, fiscal region state selections, and immediate verification of external document numbers.
For generating accompanying Brazilian payment payloads, test the brazil pix generator. To generate realistic companion user data like full names and addresses, use the mock data generator.
Usage Guide & CLI/Code Examples
- Select your document type: CPF (11 digits for individuals) or CNPJ (14 digits for corporate entities).
- Choose your formatting preference: Com Pontuação (standard punctuation) or Apenas Números (unformatted digits).
- If generating CPF numbers, pick a specific Brazilian State / Fiscal Region (for example, SP for São Paulo or RJ/ES for Rio de Janeiro).
- Set the desired batch quantity from 1 up to 50 documents.
- Click the Gerar Documentos button to compute valid numbers with verified checksum digits.
- Click the Copy icon beside any individual number or use Copy All to grab the batch for testing.
- Switch to the Validador tab to paste any existing document number and inspect its validity and regional origin.
Syntax & Specification Reference
CPF verification algorithm uses Modulo 11 with weights from 10 down to 2 for the first check digit, and weights from 11 down to 2 for the second check digit.
CNPJ verification algorithm uses Modulo 11 with cyclical weights [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2] for the first check digit, and [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2] for the second check digit.
Filters invalid repeated number patterns (such as 111.111.111-11 or 000.000.000-00) that pass naive modulo formulas but are rejected by Receita Federal systems.
Extracts the 9th digit of CPF numbers to determine the exact Brazilian Fiscal Region (Região Fiscal 1 through 0).
Standard corporate branch root 0001 is applied for main company headquarters, while custom branch indices test filial structures.
Technical Implementation Notes
- Software quality assurance engineers validating registration forms, checkout flows, and backend customer APIs.
- Database architects generating synthetic mock customer datasets for load testing and staging migrations.
- Compliance developers confirming that enterprise customer onboarding pipelines reject malformed tax numbers.
Edge Cases & Compatibility
Check digit calculation resulting in 10 or 11:
Official Receita Federal rules specify that when the remainder calculation yields 10 or 11, the resulting check digit defaults to 0.Unformatted input normalization:
The validator automatically strips non-numeric characters, leading spaces, and punctuation symbols before applying Modulo 11 weights.
Frequently Asked Questions
Are the generated CPF and CNPJ numbers real citizen records?
No. The generated numbers are mathematically valid according to the official Modulo 11 checksum algorithm, but they are synthesized randomly for software testing and do not correspond to real citizens or registered companies.
How does the 9th digit of a CPF indicate the Brazilian fiscal state?
The 9th digit identifies the issuing fiscal region: 1 is DF/GO/MT/MS/TO, 2 is AC/AP/AM/PA/RO/RR, 3 is CE/MA/PI, 4 is AL/PB/PE/RN, 5 is BA/SE, 6 is MG, 7 is ES/RJ, 8 is SP, 9 is PR/SC, and 0 is RS.
Can I validate a batch of multiple CPF or CNPJ numbers at once?
Yes. The checksum validator accepts bulk multi-line inputs, verifying each document line by line and reporting its Modulo 11 validity status.
How is the Modulo 11 check digit calculated for a Brazilian CPF?
The first nine digits are multiplied by descending weights from 10 to 2, summed, and divided by 11. If the remainder is under 2, the first check digit is 0; otherwise it is 11 minus the remainder. The second check digit repeats the calculation across the first ten digits with weights from 11 to 2.
What does the 0001 branch identifier represent in a CNPJ number?
In a 14-digit CNPJ (XX.XXX.XXX/0001-ZZ), the four digits after the slash identify the business establishment: 0001 designates the company headquarters (matriz), while 0002 and higher designate branch offices (filiais).