X12 270/271 N402 (State or Province Code): Format, Values, and Testing Notes
N402 is only two characters, so it's easy to assume there's nothing to test — but those two characters are the piece that ties a city name to the right postal code, and the segment does nothing to enforce that connection for you.
N402 is the second element of the N4 segment in an X12 271 response — a coded field that carries the two-letter state or province abbreviation for the address described by the surrounding N3 and N4 segments.
What this element carries
Example
N402 = OH, the state code that should be consistent with both the city in N401 and the ZIP code range in N403. Synthetic 271 response data.
Where this trips people up
Because N402 is validated as a code value on its own — is it a real two-letter abbreviation — rather than against the other two address elements, a file can pass segment-level validation while pairing a legitimate state code with a city or ZIP from an entirely different state. Systems that stop checking once the code format looks correct never catch this, and the inconsistency only surfaces when a downstream address-verification service rejects the combination.