Schema Tax

Tax ID Validation: How to Check Any TIN Format

By Schema TaxPublished Updated

Tax ID validation means working out which kind of taxpayer identification number you have, then testing it against that type's rules: nine digits, hyphens in the right place, and no part that the issuer never assigns. It tells you a number could be real. Only the issuing agency can confirm it belongs to a given name.

Which TIN type is this tax ID?

A taxpayer identification number (TIN) is the number the IRS uses to tie a return or form to a person or entity. A tax ID is one of four common types: a Social Security number (SSN), an employer identification number (EIN), an individual taxpayer identification number (ITIN) or an adoption taxpayer identification number (ATIN).

The IRS page on taxpayer identification numbers says the Social Security Administration issues SSNs and the IRS issues all other TINs. It describes the EIN as a number used to identify a business entity, the ITIN as a tax processing number for certain resident and nonresident aliens, and the ATIN as a temporary nine-digit number for a child in a pending adoption.

All four have nine digits. What separates them is the hyphen layout and the leading digits. The IRS General Instructions for Certain Information Returns say SSNs, ITINs and ATINs are written as 000-00-0000 and EINs as 00-0000000. The same instructions say the TIN for individual recipients is the SSN, ITIN or ATIN, while corporations, partnerships and estates use an EIN.

On forms, employer and payer boxes usually hold an EIN and employee and recipient boxes usually hold an SSN, with ITINs and ATINs allowed for 1099 recipients but not, under the IRS General Instructions for Forms W-2 and W-3, for W-2 employees. The box-by-box table is in the post on which ID belongs in which box on a W-2 or 1099, and the same post works through unlabeled numbers in detail.

The pattern tests every tax ID validation should run

Tax ID validation runs the same four tests on every number before any type-specific rule: the length is nine digits, every character other than hyphens is a digit, the hyphens sit where the type puts them, and no part falls in a range the issuer never assigns. A number that fails any test is not a valid TIN.

Length. Strip spaces and hyphens and count. Anything other than nine digits fails. Eight digits often means a leading zero was lost in a spreadsheet.

Digits only. Letters, periods and stray characters fail. The exception is a masked value such as XXX-XX-1234, which is not invalid but is not testable either.

Hyphen placement. One hyphen after the second digit is EIN layout. Two hyphens, after the third and fifth digits, is the layout shared by SSNs, ITINs and ATINs. A number with no hyphens is ambiguous and needs the type from context.

Impossible ranges. Each type has values that are never issued, and each has its own rules:

Here is the decision table that routes a nine-digit number to its type and the rules to apply next. The example values use X for any digit.

Example shapeHyphensFirst digitFourth and fifth digitsRoute toRules to apply
XX-XXXXXXXOne, after digit 2AnyNot usedEINPrefix on the IRS list
XXX-XX-XXXXTwo0 to 8AnySSNArea, group and serial rules
9XX-93-XXXXTwo993ATINFixed 93 middle digits
9XX-XX-XXXXTwo9Not 93ITINITIN middle-digit ranges
XXXXXXXXXNoneAnyAnyUnknownTake the type from the form box

Running the tests on example values

Five fictional values show how the tests fail in practice. Each one breaks a different rule, so each needs a different fix.

Example value (fictional)Test it failsLikely cause
4XXXXXXX (eight digits)LengthA leading zero lost in a numeric column, or a dropped digit
1XX-XX-12O4Digits onlyThe letter O read or typed in place of a zero
20X-XX-XXXX on an EIN lineHyphen placementAn SSN-layout number in an EIN box, or a misplaced hyphen
666-12-3456Impossible rangeSSN area 666 is never issued
07-1234567Impossible rangePrefix 07 is not on the IRS EIN list

The causes column matters as much as the result. A length failure usually points to the import step, so fixing one row by hand leaves the next file broken. A letter in place of a digit often comes from reading a scan. A hyphen in the wrong place can be a real number in the wrong box, such as a sole proprietor's SSN on a payer line, which the information-return instructions allow. Record the failed rule with the row so the person reviewing it knows where to look.

What can tax ID validation prove, and what can't it?

Tax ID validation can prove a number is impossible. It cannot prove a number is real, current, or issued to the name beside it. A format check looks at digits alone, so any plausible string passes, including a made-up one and a real one typed next to the wrong person.

A pass is still worth having. It catches transposed or dropped digits that land in a forbidden range, numbers copied from the wrong box, and a value split across two fields. It is also cheap: it runs offline, on every row, with no data leaving your system.

What a pass does not show is just as specific. It does not show the IRS or SSA issued the number. It does not show the number belongs to the payee. For an ITIN, it does not show the number is current. The IRS manual section on the ITIN Real-Time System, IRM 3.21.263 says ITINs not used on a federal return in three consecutive tax years expire, and the digits do not change when that happens.

There is also no checksum to lean on. US TINs carry no check digit, which the post on why US TINs have no check digit explains. A one-digit typo that stays inside a valid range passes every format test.

TIN validation services and when a pattern test is enough

A TIN validation service checks a name and number pair against the issuer's records, which a pattern test cannot do. The IRS runs one for payers, called TIN Matching, which compares a name and TIN pair with IRS records before information returns are filed.

Who can sign up, and what it returns, is covered in the post on who can use IRS TIN Matching.

A pattern test is enough when the question is whether data survived its trip intact. Reading a stack of W-2s into a spreadsheet, checking an export before it goes to a client, or screening a CSV for broken rows are all format problems. The number on the form is whatever the issuer printed, and the test checks that it arrived in your data unchanged.

A matching service is the next step when the question is whether the number belongs to that payee. Payers filing information returns, and anyone taking a new vendor's TIN, have that question. Run the pattern test first anyway: there is no reason to send a number that cannot exist.

Masked and partial tax IDs: a TIN validation edge case

A masked tax ID shows only part of the number, usually the last four digits, as in XXX-XX-1234. TIN validation on a masked value can check its layout and that the visible digits are digits, but not the area, prefix or range rules, which live in the hidden part.

Masked numbers are normal on the copies people receive. The information-return instructions allow a filer to truncate a payee's TIN on payee statements by replacing "the first five digits of the nine-digit number with asterisks (*) or Xs." They also say a filer may not truncate a payee's TIN on forms filed with the IRS, and that a filer's own TIN may not be truncated on any form.

That gives a useful asymmetry when you validate data read from recipient copies:

  • A masked recipient TIN is expected. Check that it has nine positions in 3-2-4 or 2-7 layout and that the last four are digits.
  • A masked payer or employer TIN is unexpected. The rules say it should be complete, so flag it.
  • A serial of 0000 in the visible digits fails SSN rules even when the rest is masked.

For matching records, the last four digits plus a name, form type and tax year are usually enough to pair a form with the right person. TIN Matching compares a TIN and name combination against IRS records, so a masked value cannot be checked that way.

Writing tax ID validation into a spreadsheet or code

Tax ID validation in a spreadsheet or in code follows one order: classify by layout and leading digits, then apply that type's rules. Keep the TIN as text from import onward, because a numeric column drops leading zeros and every later test then fails for the wrong reason.

In Excel or Google Sheets, this formula labels a hyphenated value in A2 by type. It is a router, not a full validator:

=IF(MID(A2,3,1)="-", "EIN",
  IF(AND(MID(A2,4,1)="-", MID(A2,7,1)="-"),
    IF(LEFT(A2,1)="9",
      IF(MID(A2,5,2)="93", "ATIN", "ITIN or other IRS number"),
      "SSN"),
    "Unknown: check the form box"))

Here is how it labels example values:

Example value (fictional)LabelNext check
20-XXXXXXXEINPrefix 20 on the IRS list
1XX-XX-XXXXSSNArea, group and serial rules
9XX-93-XXXXATINNone beyond layout
9XX-7X-XXXXITIN or other IRS numberITIN middle-digit ranges
XXXXXXXXXUnknown: check the form boxTake the type from the box label

In code, use one regex per type rather than one large pattern, so a failure tells you which rule broke. Run them in the order of the decision table, and store the result next to the value: the type you inferred and the rule that failed, if any. The type-specific posts give a tested regex for EIN format validation and for SSN format validation.

When the numbers come from scanned forms rather than typed entry, validation pairs well with extraction. Schema Tax reads each TIN into a named field, tests it against its pattern and flags anything uncertain for review on an editable view of the form, as its five-step process shows. Developers building this into their own systems will find related patterns in the tax form API guides.

All posts in Accuracy and Security