Generate valid CPF numbers instantly for testing. Free online tool creates compliant Brazilian tax IDs that pass validation. Perfect for developers and QA teams.
A CPF generator creates valid, random CPF (Cadastro de Pessoas FĂsicas) numbers for software testing and development. The CPF is Brazil's unique identification number assigned to citizens and residents for tax purposes. This free online CPF generator produces properly formatted numbers that pass validation algorithms, perfect for testing Brazilian applications without using real personal data.
Important: Generated CPFs are for testing only and are not associated with real individuals. Never use them for fraudulent activities or to impersonate actual people.
A valid CPF consists of 11 digits with a specific structure:
Example: 123.456.789-09
The check digits ensure the CPF number is mathematically valid, preventing typos and invalid entries in Brazilian systems.
The CPF validation algorithm ensures number integrity through a mathematical check:
Step-by-step validation process:
This validation prevents random number sequences from being accepted as valid CPFs.
Using our free CPF generator is simple and instant:
The tool generates compliant CPF numbers that pass all validation checks, making it perfect for development and QA testing.
The formula for generating a valid CPF is as follows:
1def generate_cpf():
2 # Generate 9 random digits
3 base_cpf = [random.randint(0, 9) for _ in range(9)]
4
5 # Calculate first check digit
6 sum_1 = sum((10 - i) * digit for i, digit in enumerate(base_cpf))
7 check_digit_1 = (sum_1 * 10 % 11) % 10
8
9 # Calculate second check digit
10 sum_2 = sum((11 - i) * digit for i, digit in enumerate(base_cpf + [check_digit_1]))
11 check_digit_2 = (sum_2 * 10 % 11) % 10
12
13 return base_cpf + [check_digit_1, check_digit_2]
14The generator performs the following steps:
Here are some examples of generated CPFs:
A CPF generator is essential for various software development and testing scenarios:
While the CPF is the primary individual identifier in Brazil, there are other identifiers that may be used in specific contexts:
The CPF was introduced in Brazil in 1965 as part of a broader effort to modernize the country's tax system. Initially, it was used primarily for income tax purposes, but over time, its use expanded to various other areas of Brazilian bureaucracy and commerce.
Key milestones in CPF history:
Today, the CPF is an essential part of Brazilian citizens' and residents' interactions with government services, financial institutions, and many commercial transactions.
Here are code snippets for generating and validating CPFs in various programming languages:
1import random
2
3def generate_cpf():
4 cpf = [random.randint(0, 9) for _ in range(9)]
5 for _ in range(2):
6 value = sum((cpf[num] * ((len(cpf) + 1) - num) for num in range(len(cpf)))) % 11
7 cpf.append(11 - value if value > 1 else 0)
8 return ''.join(map(str, cpf))
9
10def validate_cpf(cpf):
11 numbers = [int(digit) for digit in cpf if digit.isdigit()]
12 if len(numbers) != 11 or len(set(numbers)) == 1:
13 return False
14 for i in range(9, 11):
15 value = sum((numbers[num] * ((i + 1) - num) for num in range(i))) % 11
16 if numbers[i] != (11 - value if value > 1 else 0):
17 return False
18 return True
19
20## Example usage
21cpf = generate_cpf()
22print(f"Generated CPF: {cpf}")
23print(f"Is valid: {validate_cpf(cpf)}")
241function generateCPF() {
2 const cpf = Array.from({length: 9}, () => Math.floor(Math.random() * 10));
3 for (let i = 0; i < 2; i++) {
4 let sum = cpf.reduce((acc, cur, idx) => acc + cur * (cpf.length + 1 - idx), 0);
5 let digit = 11 - (sum % 11);
6 cpf.push(digit > 9 ? 0 : digit);
7 }
8 return cpf.join('');
9}
10
11function validateCPF(cpf) {
12 const numbers = cpf.match(/\d/g).map(Number);
13 if (numbers.length !== 11 || new Set(numbers).size === 1) return false;
14 for (let i = 9; i < 11; i++) {
15 let sum = numbers.slice(0, i).reduce((acc, cur, idx) => acc + cur * (i + 1 - idx), 0);
16 let digit = 11 - (sum % 11);
17 if (numbers[i] !== (digit > 9 ? 0 : digit)) return false;
18 }
19 return true;
20}
21
22// Example usage
23const cpf = generateCPF();
24console.log(`Generated CPF: ${cpf}`);
25console.log(`Is valid: ${validateCPF(cpf)}`);
261import java.util.Random;
2
3public class CPFGenerator {
4 private static final Random random = new Random();
5
6 public static String generateCPF() {
7 int[] cpf = new int[11];
8 for (int i = 0; i < 9; i++) {
9 cpf[i] = random.nextInt(10);
10 }
11 cpf[9] = calculateCheckDigit(cpf, 10);
12 cpf[10] = calculateCheckDigit(cpf, 11);
13 return formatCPF(cpf);
14 }
15
16 private static int calculateCheckDigit(int[] cpf, int factor) {
17 int sum = 0;
18 for (int i = 0; i < factor - 1; i++) {
19 sum += cpf[i] * (factor - i);
20 }
21 int result = 11 - (sum % 11);
22 return result > 9 ? 0 : result;
23 }
24
25 private static String formatCPF(int[] cpf) {
26 return String.format("%d%d%d.%d%d%d.%d%d%d-%d%d",
27 cpf[0], cpf[1], cpf[2], cpf[3], cpf[4], cpf[5], cpf[6], cpf[7], cpf[8], cpf[9], cpf[10]);
28 }
29
30 public static boolean validateCPF(String cpf) {
31 cpf = cpf.replaceAll("[^0-9]", "");
32 if (cpf.length() != 11) return false;
33 int[] numbers = cpf.chars().map(Character::getNumericValue).toArray();
34 if (allEqual(numbers)) return false;
35 int digit10 = calculateCheckDigit(numbers, 10);
36 int digit11 = calculateCheckDigit(numbers, 11);
37 return numbers[9] == digit10 && numbers[10] == digit11;
38 }
39
40 private static boolean allEqual(int[] array) {
41 for (int i = 1; i < array.length; i++) {
42 if (array[i] != array[0]) return false;
43 }
44 return true;
45 }
46
47 public static void main(String[] args) {
48 String cpf = generateCPF();
49 System.out.println("Generated CPF: " + cpf);
50 System.out.println("Is valid: " + validateCPF(cpf));
51 }
52}
53These examples demonstrate how to generate and validate CPFs in Python, JavaScript, and Java. You can adapt these functions to your specific needs or integrate them into larger systems that require CPF handling.
Yes, this CPF generator is completely free with no registration required. Generate as many valid CPF numbers as needed for your testing purposes.
No. While the numbers are mathematically valid and pass validation algorithms, they are randomly generated and not associated with real individuals. They should only be used for testing.
Never use generated CPFs in production environments. Production systems must use real, verified CPFs provided by actual users or authorized sources.
The generator implements Brazil's official CPF algorithm, calculating both check digits correctly to produce numbers that pass all standard validation tests.
CPF is for individuals (citizens and residents), while CNPJ (Cadastro Nacional da Pessoa JurĂdica) is used for businesses and legal entities in Brazil.
Generating CPF numbers for legitimate testing and development purposes is legal. However, using them fraudulently or to impersonate real people is illegal and unethical.
While theoretically possible, the probability is extremely low given the 100 billion possible valid CPF combinations. Each generation is random and independent.
Yes. Generated CPFs will pass standard validation algorithms, making them perfect for testing form validation, input sanitization, and data formatting in applications.
When using a CPF generator, follow these important guidelines:
Ready to test your Brazilian application? Use our free CPF generator to create valid test data instantly. Generate compliant CPF numbers that pass all validation checks, perfect for development, testing, and QA environments. Click the button above to get started.
Meta Title: CPF Generator - Free Brazilian Tax ID for Testing Meta Description: Generate valid CPF numbers instantly for testing. Free online tool creates compliant Brazilian tax IDs that pass validation. Perfect for developers and QA teams.
Discover more tools that might be useful for your workflow