Magnetic Stripe Track Data
ISO/IEC 7813 defines two record formats for magnetic stripes. Track 1 is alphanumeric and carries the cardholder name alongside the PAN; Track 2 is numeric and carries the PAN, expiry, service code and discretionary data. Both use sentinel characters and field separators. This reference gives the byte-level layout of each, the field lengths, the service code meanings and the character sets involved, with worked examples.
Track 1 and Track 2
ISO/IEC 7813 defines two record formats for the magnetic stripe. Track 1 is alphanumeric and carries the cardholder name. Track 2 is numeric and carries the PAN, expiry, service code and discretionary data. Both begin with a sentinel character, separate fields with a separator and end with a terminator.
- Track 1 is alphanumeric and includes the cardholder name
- Track 2 is numeric and omits the name
- Each record starts with a sentinel and ends with a terminator
- Fields are separated by a single delimiter
- Both encode the PAN and the expiry
Field layout
Track 1 fields run format code, primary account number, name, expiry, service code and discretionary data. Track 2 fields run primary account number, expiry, service code and discretionary data. The service code occupies a fixed three-digit position and controls whether the card may be used for local or international transactions.
- Track 1: format code, PAN, name, expiry, service code, discretionary
- Track 2: PAN, expiry, service code, discretionary
- The service code is a fixed three-digit field
- The first service code digit governs international use
- The second governs local use
Expiry and service codes
The expiry is stored as a two-digit year and a two-digit month, and in Track 1 the two digits are reversed compared with Track 2. The service code tells the terminal what the card is authorised for, which is why a card with a restricted service code behaves differently at different terminals.
- Expiry is stored as YYMM
- Track 1 reverses the expiry digit order relative to Track 2
- Service code digit one controls international use
- Service code digit two controls local use
- Digit three indicates PIN support and interchange requirements
Reading a record safely
A parser should validate structure before trusting content: correct sentinel, correct field count, correct separators, a PAN that passes the Luhn check, and a plausible expiry. Records that fail these checks are malformed, and malformed records are a strong indicator of a bad or tampered source.
- Validate the sentinel and terminator
- Check the field count and separators
- Confirm the PAN passes the Luhn check
- Confirm the expiry is plausible
- Reject records that fail any structural check
Frequently Asked Questions
What is magnetic stripe track data?
The two record formats defined in ISO/IEC 7813 for data stored on a card's magnetic stripe.
What is the difference between Track 1 and Track 2?
Track 1 is alphanumeric and includes the cardholder name; Track 2 is numeric and does not.
How is expiry encoded?
As a two-digit year and month, in reversed order in Track 1 compared with Track 2.
What does the service code control?
Whether the card may be used for local and international transactions, and whether PIN is supported.
How do I validate a record?
Check the sentinel, separators, field count, Luhn validity of the PAN and the plausibility of the expiry.