IBGE UF Code Validator
Validate IBGE UF code (2 digits: 11-53). Covers the 27 official codes and shows UF and name.
UF IBGE code validation: 2 digits, 27 valid states, non-consecutive numbering
The UF IBGE code is a 2-digit numeric identifier assigned by IBGE (Instituto Brasileiro de Geografia e Estatistica) to each Brazilian federative unit โ the 26 states plus the Federal District. It is the canonical code used in NF-e, eSocial, CNAE, georeferencing datasets and federal statistics. Validating it means more than checking that the input has two digits: only 27 specific values are legal, and the numbering is intentionally non-consecutive.
The risk of mistaking the UF IBGE code for a generic 2-digit number is real: invoice systems that hardcode 00..99 as the allowed range silently accept invalid codes like 34 or 44, and Sefaz only catches the error at submission time, returning rejection 247 ("UF do destinatario invalida") or 251 ("cUF nao corresponde ao emitente").
The complete table of 27 valid codes
The IBGE codes are organized by region; the first digit reflects the geographic region.
- Norte (1x): 11 RO (Rondonia), 12 AC (Acre), 13 AM (Amazonas), 14 RR (Roraima), 15 PA (Para), 16 AP (Amapa), 17 TO (Tocantins).
- Nordeste (2x): 21 MA (Maranhao), 22 PI (Piaui), 23 CE (Ceara), 24 RN (Rio Grande do Norte), 25 PB (Paraiba), 26 PE (Pernambuco), 27 AL (Alagoas), 28 SE (Sergipe), 29 BA (Bahia).
- Sudeste (3x): 31 MG (Minas Gerais), 32 ES (Espirito Santo), 33 RJ (Rio de Janeiro), 35 SP (Sao Paulo).
- Sul (4x): 41 PR (Parana), 42 SC (Santa Catarina), 43 RS (Rio Grande do Sul).
- Centro-Oeste (5x): 50 MS (Mato Grosso do Sul), 51 MT (Mato Grosso), 52 GO (Goias), 53 DF (Distrito Federal).
Total: 27 valid codes. Any input outside this set is invalid โ there is no escape hatch.
The gaps: why 18, 19, 20, 30, 34, 36-40, 44-49 do not exist
A classic source of bugs in NF-e validators is the assumption that UF codes are sequential. They are not. The original 1976 IBGE resolution numbered the states in regional order with deliberate room for growth:
- 18, 19, 20: never assigned. Reserved for hypothetical future divisions of the North region. After Tocantins (17) was created from Goias in 1988, IBGE refused to fill 18-20 โ they remain the legacy buffer of the old North.
- 30: never assigned. Acted as the separator between the last Northeast code (29 BA) and the Sudeste range.
- 34: vacancy in Sudeste. SP took 35 directly from the original table because of its prominence; 34 was reserved for an extra Sudeste UF that never materialized.
- 36 to 40: buffer between Sudeste and Sul.
- 44 to 49: buffer between Sul and Centro-Oeste.
The lesson: never validate a UF code with code >= 11 && code <= 53. Always look up against the explicit set of 27 codes.
Reference implementation
const VALID = new Set([
11,12,13,14,15,16,17,
21,22,23,24,25,26,27,28,29,
31,32,33,35,
41,42,43,
50,51,52,53
])
function validUfIbge(input) {
const re = /^\d{2}$/
if (!re.test(input)) return { ok: false, error: 'format' }
const code = parseInt(input, 10)
if (!VALID.has(code)) return { ok: false, error: 'code does not exist' }
return { ok: true, code }
}
Code vs sigla: two parallel notations
Brazilians identify a state in two ways: the 2-letter sigla (SP, RJ, MG) and the 2-digit IBGE code (35, 33, 31). Both are official and unambiguous, but they appear in different contexts:
- Sigla: license plates, ZIP-code prefixes (CEP), street addresses, postal labels, journalism.
- Code: NF-e (cUF tag), eSocial, FGTS, INSS files, IBGE statistics, government XML files, CNES.
When integrating different systems, both must be available in your lookup table. BrasilAPI exposes a free read-only endpoint: GET https://brasilapi.com.br/api/ibge/uf/v1 returns the canonical list with code, sigla and full name.
Use cases that demand validation
- NF-e tag
cUF: the IBGE code of the issuer's state, used by Sefaz to route the document to the correct UF webservice. Wrong cUF returns rejection 247 or 251. - eSocial S-1000: the employer's UF code is mandatory in the company registration event.
- Municipal codes: the IBGE municipal code (7 digits) starts with the UF code; validating the prefix catches typos before downstream lookups.
- Georeferenced datasets: DataSUS, INEP, IPEA tables key everything on the IBGE UF code.
- Statistics and BI: most public datasets join state-level data via the IBGE code, not the sigla.
Historical note: TO and the 1988 expansion
The original 1976 IBGE table had 26 states. Tocantins (code 17) was created by the 1988 Constitution from northern Goias, and IBGE squeezed it into the North block โ preserving the 1x prefix discipline. No previous code was rewritten, which is why so much legacy software has Tocantins missing entirely instead of incorrect.
Other 1988-era candidate states (Triangulo Mineiro, Sao Francisco, Maranhao do Sul) never materialized, leaving the reserved gaps intact. Any new UF would receive a new code from the next available slot, not a recycled one.
FAQ
Are the codes consecutive? No. There are deliberate gaps (18, 19, 20, 30, 34, 36-40, 44-49). Always validate against the explicit set of 27 codes, never against a range.
When does the table change? Only when a new federative unit is created or an existing one is split โ neither has happened since Tocantins in 1988. The table is stable for practical purposes.
Is there a free official API? Yes. IBGE's localidades endpoint (servicodados.ibge.gov.br/api/v1/localidades/estados) is free and unauthenticated; BrasilAPI proxies the same data with simpler payloads.
Why is SP code 35 and not 34? Code 34 was reserved as a future-growth slot for Sudeste; SP, the largest Sudeste UF, anchored the next available even-significant number (35) in the original 1976 table. The reservation was never used.
Can I confuse the IBGE UF code with a GS1 country prefix? No. GS1 prefixes for Brazil are 789-790 (3 digits, on EAN/UPC barcodes) and serve a different purpose. They share no overlap with IBGE UF codes.
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.