CNH Validator
Validate Brazilian driver's license (CNH) numbers using the official DETRAN algorithm. No data sent to servers.
How does CNH validation work?
A CNH number has 11 digits: 9 base digits plus 2 check digits. DETRAN works them out through weighted multiplication, one pass decreasing and one increasing, with modulo 11. The algorithm also takes a state factor (DSC) that can be 0 or 1.
All of the checking happens right in your browser.
CNH validation: modulo 11 with the global decrement rule
The CNH (Carteira Nacional de Habilitacao) is the Brazilian driver's license, issued by the state DETRAN (Departamento Estadual de Transito) under the rules of the federal SENATRAN (Secretaria Nacional de Transito) and the CTB — Codigo de Transito Brasileiro, Lei 9.503/1997. Every license carries an 11-digit number printed at the back, also referred to as the numero de registro. This number is independent of the RENACH (Registro Nacional da Carteira de Habilitacao), the lifetime national identifier shared between every CNH issued to the same driver.
A pure offline validator like this one runs the modulo 11 algorithm with a small wrinkle that does not exist in CPF, CNPJ or PIS: the decrement rule. When DV1 is calculated as 10, both DV1 is forced to 0 and the entire DV2 calculation uses a global decrement that shifts the second-pass weights down by one. This is the most common reason for buggy custom validators on the internet — most copy the CPF code and skip the decrement branch.
Computing DV1
- Take the first 9 digits and multiply, in order, by weights 9, 8, 7, 6, 5, 4, 3, 2, 1.
- Sum the products and compute the remainder modulo 11.
- If the remainder equals 10, set
decrement = 2and DV1 = 0; otherwise DV1 = remainder.
Computing DV2 (with optional decrement)
- Take the first 9 digits and multiply, in reverse order, by weights 1, 2, 3, 4, 5, 6, 7, 8, 9.
- Sum the products and compute the remainder modulo 11.
- Subtract the decrement (0 or 2) from the remainder; if the adjusted value is negative or equals 11, DV2 = 0; otherwise DV2 = adjusted remainder.
function validateCNH(s) {
const d = s.replace(/\D/g,'').padStart(11,'0');
if (!/^\d{11}$/.test(d)) return false;
if (/^(\d)\1{10}$/.test(d)) return false;
let dec = 0, dv1 = 0, dv2 = 0, sum = 0;
for (let i = 0, w = 9; i < 9; i++, w--)
sum += parseInt(d[i]) * w;
let r = sum % 11;
if (r >= 10) { dec = 2; dv1 = 0; } else dv1 = r;
sum = 0;
for (let i = 0, w = 1; i < 9; i++, w++)
sum += parseInt(d[i]) * w;
r = sum % 11;
dv2 = r >= 10 ? 0 : r - dec;
if (dv2 < 0) dv2 += 11;
return dv1 === parseInt(d[9]) && dv2 === parseInt(d[10]);
}
As with every Brazilian document of the same family, sequences of a single repeating digit must be rejected even though they pass the algebra.
CNH categories, the EAR badge and the CTB
The CTB defines six driving categories that may be combined on the same physical card:
- ACC — Autorizacao para Conduzir Ciclomotor. Mopeds up to 50 cc.
- A — motorcycles, motorized tricycles, motonetas.
- B — passenger cars up to 3,500 kg and up to 8 passengers, the default category for civilians.
- C — vehicles between 3,500 kg and 6,000 kg or with more than 8 seats. Required for light trucks.
- D — buses, vans and any vehicle for more than 8 passengers. Required for public transport, school transport.
- E — articulated vehicles, semi-trailers, combinations above 6,000 kg.
The EAR badge — Exerce Atividade Remunerada — is an annotation on the physical card and the digital CNH stating that the driver is authorized to perform paid driving activities. It is the document that ride-sharing apps (Uber, 99, InDrive), delivery apps (iFood, Rappi) and car-rental companies (Localiza, Movida, Unidas) check during onboarding, in addition to the category and the photo.
CNH Digital, RENACH and validity
Since 2017 the federal DENATRAN — now SENATRAN — supports the CNH Digital, an electronic copy accessible through the Carteira Digital de Transito (CDT) app or the gov.br Carteira de Trabalho dashboard. The digital version embeds a QR Code that any DETRAN agent or contracted authority can scan online to confirm authenticity in real time; the QR contains a signed payload tied to the RENACH.
The RENACH is a national lifetime ID. When a driver moves between states or renews the license, the 11-digit numero de registro changes, but the RENACH stays the same — that is how SENATRAN keeps a single timeline of training, infractions and points across the country.
Validity follows Law 14.071/2020: 10 years for drivers under 50, 5 years for ages 50 to 69, 3 years for 70 and over. EAR holders renew on a tighter cycle and undergo additional medical and psychological exams.
Use cases for an offline CNH validator
- Driver onboarding flows in delivery and ride-sharing apps — pre-check before uploading a photo of the document.
- Car-rental online forms (Localiza, Movida, Unidas), to reject typos before charging the credit card.
- Insurance quote forms that gather the driver number for the policy.
- Fleet-management software validating driver CRUD operations.
- Government portals integrating with the gov.br ID stack.
For deep integration, SENATRAN exposes restricted APIs to authorized integrators (insurers, telematics vendors, public agencies). State-level DETRANs (notably DETRAN-SP and DETRAN-RJ) offer limited web consultation flows for the driver themselves through gov.br login.
Points, suspension and what the validator does NOT check
A valid 11-digit number does not mean the license is currently active. A driver may be suspended or cassada while keeping the same number. Under Law 14.071/2020 the suspension threshold is dynamic: 20 points if the driver has at least two serious or very serious infractions, 30 points if there is up to one, and 40 points if none. EAR holders use a different scale that varies by activity. None of this is encoded in the 11-digit number — only an online consultation tells you the current status.
FAQ
Is the CNH Digital number different from the physical card?
No. The digital and physical CNH refer to the same document, the same 11-digit numero de registro and the same RENACH. The digital version adds a QR Code for online verification but does not change the identifiers.
Does the validator confirm the license is active?
No. It only confirms the 11 digits satisfy the modulo 11 algorithm including the decrement rule. Active status, points balance and suspensions require an authenticated query to the DETRAN of the issuing state.
Is the International Driving Permit validated by the same algorithm?
No. The Permissao Internacional para Dirigir (PID) is a translated companion issued by the DETRAN; it carries the same RENACH but follows a separate numbering and is validated through diplomatic channels in each destination country.
Can the number change when I renew?
Yes. The 11-digit numero de registro is regenerated by the issuing DETRAN at each renewal or state transfer. The RENACH stays constant for life.
Are leading zeros valid?
Yes, and they are significant. Legacy registries occasionally hand out numbers padded with zeros at the front; never strip them silently.
Related Tools
CPF Validator
Validate Brazilian CPF numbers instantly using the official algorithm. Useful for testing document validation in applications. No data sent to servers.
Batch CPF Validator
Validate a list of CPFs (one per line) and see which are valid and which are not. No data sent to servers.
Batch CNPJ Validator
Validate a list of CNPJs (one per line) with a summary of valid, invalid and total. No data sent to servers.
Driver's licence number validator
The CNH number carries check digits calculated by the algorithm the DETRANs use, and checking them catches typos before you go ahead with a registration. The validator reruns that calculation and tells you right after whether the number is valid.
It earns its keep before a spreadsheet import, when you're going over a driver registration, or whenever a vehicle-rental form lands on your desk. What it confirms is the number's mathematical consistency, and it does that without ever hitting a DETRAN system.
The whole validation runs in the browser, with no data sent to servers. It's free and private, good for checking CNH numbers safely.