NCM Code Validator
Validate NCM format (8 numeric digits). Decomposes into chapter (2), position (2), subposition (2), item (2). No official table check.
NCM validation: from regex to TIPI lookup
The NCM (Nomenclatura Comum do Mercosul) is the 8-digit fiscal classification that determines how a product is taxed when it crosses Brazilian borders or moves through the domestic supply chain. Validating an NCM is a multi-layer process: it is not enough to confirm that the input has 8 digits โ the code must also exist in the current TIPI and be hierarchically coherent.
An NCM is conventionally displayed in the mask CC.CC.CC.CC, but Sefaz accepts both the dotted form and the bare 8-digit string. A robust validator must therefore normalize the input, run a regex check, then look it up against the official table.
The 6+2 hierarchy: WCO Harmonized System plus Mercosur
The 8 digits decompose into two semantic blocks:
- Digits 1-6 (SH): the Sistema Harmonizado, maintained by the World Customs Organization (WCO) and shared by more than 200 countries. Digits 1-2 are the Capitulo (chapter), 3-4 the Posicao (heading) and 5-6 the Subposicao (subheading).
- Digits 7-8 (Mercosul-specific): Item (digit 7) and Subitem (digit 8), added by Mercosur to refine taxation when SH granularity is insufficient.
Example: NCM 87.03.23.10 means Chapter 87 (vehicles), heading 03 (passenger cars), subheading 23 (engine 1500-3000 cc), item 1 and subitem 0 (specific Mercosur breakdown for cars with spark-ignition engines and cylinder capacity 1500-3000 cm3).
Three layers of validation
A serious NCM validator runs the input through three sequential checks:
// 1. Format
const re = /^\d{2}\.?\d{2}\.?\d{2}\.?\d{2}$/
if (!re.test(input)) return { ok: false, error: 'format' }
const ncm = input.replace(/\./g, '')
// 2. Semantic (table lookup)
const exists = await tipiTable.has(ncm)
if (!exists) return { ok: false, error: 'not in TIPI' }
// 3. Hierarchical coherence
const chapter = ncm.slice(0, 2)
const heading = ncm.slice(0, 4)
if (!validChapters.has(chapter)) return { ok: false, error: 'chapter' }
if (!validHeadings.has(heading)) return { ok: false, error: 'heading' }
return { ok: true }
TIPI: the source of truth and its annual updates
The TIPI (Tabela de Incidencia do Imposto sobre Produtos Industrializados) is the official table maintained by the Receita Federal. It lists every valid NCM together with its IPI rate. The current version is fixed by Decreto 11.158/2022 and is amended by Resolucao Camex throughout the year โ usually consolidated into a new Decreto annually. Codes can be created, modified or revoked at any of these revisions, which is why NCM validation cannot rely on a hardcoded list.
The WCO revises the underlying Harmonized System every five years (HS 2017, HS 2022, HS 2027), forcing Mercosur to realign the 6-digit prefix. The last large overhaul moved hundreds of e-commerce, electric vehicle and biotech products into new headings โ a classic source of validation failures in product catalogs that were not migrated.
Use cases that demand a valid NCM
- NF-e issuance: Sefaz rejects any electronic invoice whose NCM is not present in the current TIPI (rule N16a in the schema). The reject code
778means "NCM nao encontrado na TIPI vigente". - Import Declaration (DI / Duimp): Siscomex blocks the registration if the NCM is invalid or revoked, and computes II, IPI, PIS-Importacao and COFINS-Importacao from the code.
- Export Declaration (DU-E): required for customs clearance; wrong NCM can trigger reclassification, fines and retention of cargo at the port.
- ICMS-ST and CEST: when the product is under tax substitution, NCM is used jointly with CEST to determine the regime.
- Statistical filings: SECEX, MDIC and IBGE use NCM to compile foreign-trade statistics.
Free APIs and Brazilian libraries
The Receita Federal does not expose a clean public NCM endpoint, but the community has filled the gap. The most reliable free option is BrasilAPI:
GET https://brasilapi.com.br/api/ncm/v1/{code}
GET https://brasilapi.com.br/api/ncm/v1?search={term}
Commercial alternatives such as Soluctra, Mastersaf and SOVOS Taxweb ship a continuously updated TIPI plus historical revisions, which is mandatory for retroactive audits. Avoid hardcoding NCM lists in your product database โ set up a monthly job that pulls the latest TIPI and reconciles your SKUs.
Common validation errors
- Typo: swapped digits or missing dot โ caught by regex.
- Revoked NCM: code was valid last year but no longer exists โ caught by TIPI lookup.
- Inconsistent hierarchy: digits 7-8 reference a non-existent Mercosur item under a valid SH subheading.
- HS migration drift: catalog still references HS 2017 codes after the HS 2022 cutover.
- Pseudo-code: internal placeholders like
9999.99.99that pass regex but fail TIPI.
NCM vs HS vs TARIC: not interchangeable
Even though NCM, TARIC (EU) and HTS (US) all extend the WCO Harmonized System, they diverge after digit 6. A product correctly classified as 8703.23.10 in Brazil might be 8703.23.19.10 (10 digits) in the EU TARIC and 8703.23.01.40 in the US HTS. Cross-border catalogs must maintain a per-jurisdiction mapping; reusing the Brazilian NCM in an EU declaration is a guaranteed reclassification.
FAQ
How often is the TIPI updated? The base Decreto is usually annual, but Camex resolutions can amend it at any time. Plan for a monthly reconciliation against the official source.
Is there a free way to validate an NCM against the official table? Yes. BrasilAPI proxies the official NCM list and is free for moderate use. For high volume, mirror the table locally and refresh weekly.
Can the same product have multiple NCMs? No. Each SKU must be classified into a single NCM. If your product genuinely fits two headings, the Receita Federal accepts a consulta de classificacao request and issues a binding ruling.
What does Sefaz return when the NCM is invalid? Rejection code 778 ("NCM nao encontrado na TIPI vigente") or 779 (when the code is valid but cannot be used in the current operation type).
Does this validator query the Receita Federal? No. It runs format and hierarchical checks locally. For TIPI semantic confirmation, point your backend at BrasilAPI or a licensed tax compliance vendor.
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.