Skip to content

CPF Generator: Create a Valid Brazilian CPF Number

A CPF generator creates random Brazilian CPF tax ID numbers that pass the official check-digit algorithm, for use in software testing and form validation.

Click to generate a valid Brazilian CPF number for testing purposes

Loading calculator...
📚

Documentation

What Is a CPF Generator

A CPF generator is a tool that produces random Brazilian CPF numbers. A CPF (Cadastro de Pessoas Físicas) is an 11-digit tax identification number issued by Brazil's federal revenue service to individuals. The numbers this tool produces pass the official check-digit algorithm, but they are not registered to any real person. Developers use them to fill test forms, seed databases, and check validation code without touching real personal data.

CPF Number Format

A CPF has 11 digits, usually written as XXX.XXX.XXX-XX. The first nine digits are the base number. The last two are check digits, calculated from the first nine using a fixed formula. The check digits let software detect typos: if a single digit is mistyped, the check-digit calculation almost always fails, so invalid numbers can be rejected automatically.

Example: 123.456.789-09

How to Calculate the CPF Check Digits

Both check digits come from the same weighted-sum method, applied twice.

First check digit

  1. Multiply each of the first 9 digits by a weight, counting down from 10 to 2.
  2. Add the results together.
  3. Divide the sum by 11 and keep the remainder.
  4. If the remainder is 0 or 1, the check digit is 0. Otherwise, the check digit is 11 minus the remainder.

Second check digit

Repeat the same steps using all 10 digits so far (the original 9 plus the first check digit just calculated), with weights counting down from 11 to 2.

One pattern is always rejected: a base number made of the same digit repeated 9 times (such as 111111111) produces check digits equal to that same digit, so numbers like 111.111.111-11 pass the formula. Because of this, Brazilian systems, and this generator, treat any CPF with 11 identical digits as invalid regardless of what the formula returns.

Worked Example

Take the base digits 1, 2, 3, 4, 5, 6, 7, 8, 9.

Weights 10 down to 2 give: (1×10) + (2×9) + (3×8) + (4×7) + (5×6) + (6×5) + (7×4) + (8×3) + (9×2) = 210.

210 ÷ 11 leaves a remainder of 1. Since the remainder is under 2, the first check digit is 0.

Now use all 10 digits (1,2,3,4,5,6,7,8,9,0) with weights 11 down to 2: (1×11) + (2×10) + (3×9) + (4×8) + (5×7) + (6×6) + (7×5) + (8×4) + (9×3) + (0×2) = 255.

255 ÷ 11 leaves a remainder of 2. Since the remainder is 2 or more, the second check digit is 11 − 2 = 9.

The complete number is 123.456.789-09.

How to Use This CPF Generator

Click "Generate CPF." The tool picks nine random digits, rejects the run if all nine happen to match, then computes the two check digits from those nine using the formula above. The result is shown in XXX.XXX.XXX-XX format with a button to copy it.

Why Developers Use Generated CPFs

Real CPF numbers identify real people, and using them in test systems risks exposing personal data or violating Brazil's data protection law, the LGPD. A generated CPF solves that problem: it passes the same check-digit validation as a real one, so it exercises form validation, database constraints, and API request handling the same way a genuine number would, without any link to an actual person.

Common uses include seeding test databases, checking that a signup form rejects malformed numbers while accepting valid ones, and populating sample data for demos. Generated CPFs will not match a real record in a government database, so they are not useful for testing lookups against live Brazilian systems — only for testing the format and check-digit logic itself.

CPF vs. CNPJ

CPF identifies individuals. CNPJ (Cadastro Nacional da Pessoa Jurídica) identifies businesses and other legal entities. CNPJ has 14 digits and uses a similar but separate weighted check-digit formula. A CPF generator and a CNPJ generator are not interchangeable.

Frequently Asked Questions

Is a generated CPF linked to a real person? No. The digits are chosen at random and the check digits are calculated from them. Nothing ties the result to Brazil's Receita Federal database.

Can a generated CPF be used to open an account or file taxes? No. Systems that check a CPF against government records will reject a generated one immediately, and using it to impersonate a real filing is illegal.

Why does the tool reject numbers with all identical digits, like 111.111.111-11? Because the check-digit formula happens to accept them mathematically, but Brazilian institutions treat repeated-digit CPFs as known-invalid placeholders, never real ones. The generator filters them out and the validator rejects them too.

How many different valid CPFs are possible? The first 9 digits can be any combination from 000000000 to 999999999, which is 1,000,000,000 possibilities. The two check digits are not random; they are calculated from those 9 digits. So there are about 1 billion possible valid CPFs in total, minus the 10 repeated-digit combinations that are excluded. The odds of two independently generated CPFs matching by chance are therefore about 1 in 1 billion.

Does a generated CPF pass third-party validation libraries? Yes. Any library that checks the standard modulo-11 check-digit algorithm will accept it, because the number is built using that same algorithm.

What is the difference between CPF and RG? CPF is a federal tax number with one national format and algorithm. RG (Registro Geral) is a state-issued identity document; formats vary by state and it has no standard check-digit algorithm.

References

  1. Receita Federal do Brasil, "CPF – Cadastro de Pessoas Físicas"
  2. Lei nº 4.862, of 1965, which created the CPF system: planalto.gov.br
  3. Lei Geral de Proteção de Dados (LGPD), Brazil's data protection law: gov.br/lgpd