To convert a W2 to CSV without breaking the numbers, write one header row with a column for every box, store the EIN, ZIP code and SSN as quoted text, keep amounts as plain decimals with cents and no dollar signs, and open the file through a spreadsheet's import tool rather than by double-clicking it.
When CSV beats Excel for W2 data
CSV, short for comma-separated values, is plain text: one line per record and commas between fields. For W-2 data it beats an Excel workbook whenever the next step is another program rather than a person. Databases, accounting tools, scripts and bulk-upload screens read CSV more reliably than they read a workbook.
The format is simple enough to describe in a few rules. RFC 4180, the IETF memo that documents the CSV format, says each record sits on its own line, the first line may be an optional header of field names, and each line should contain the same number of fields. It also registers the text/csv media type. The memo is informational rather than a binding standard, which is why programs still differ in the details.
That simplicity has a price. A CSV file has no cell formats, no formulas and no notion of text versus number. Whatever opens it decides how to treat each value. A workbook can remember that a column is text, and a CSV cannot. That one difference explains most of the trouble covered in the sections below.
Use Excel when a person will read, sort and total the forms by hand. Use CSV when the file is a hand-off: an import into another system, a load into a database table, or an attachment that has to open the same way on any operating system. If you are collecting several forms at once, the guide to multiple W2s in one spreadsheet covers totals across rows. For a general comparison of the three export formats, the Excel, CSV and JSON category has the side-by-side posts.
A W2 CSV header row you can reuse
A reusable W2 CSV header row names every box once, in the order the boxes appear on the form, with names that never change from year to year. Stable column names let you append next year's forms to this year's file, and let any import tool map columns by name instead of by position.
Box labels come from the IRS General Instructions for Forms W-2 and W-3. The 2026 version lists Boxes a to f for identity, Boxes 1 to 8 and 10 to 11 for amounts, Box 12 for coded items, Box 13 for three checkboxes, Boxes 14a and 14b, and Boxes 15 to 20 for state and local lines. The instructions say "Do not enter an amount in box 9," so a header can skip it.
A sample header row and two data rows
The rows below are fictional examples. The first employee has one Box 12 code and one state. The second has two Box 12 codes and two states.
tax_year,employee_ssn_last4,employer_ein,employer_name,employer_zip,box1_wages,box2_fed_withheld,box3_ss_wages,box4_ss_withheld,box5_medicare_wages,box6_medicare_withheld,box12a_code,box12a_amount,box12b_code,box12b_amount,box13_retirement_plan,state1,state1_employer_id,box16_state1_wages,box17_state1_tax,state2,state2_employer_id,box16_state2_wages,box17_state2_tax
2026,"1234","04-5551234","Harbor Example Foods LLC","02110",48500.00,4920.00,52000.00,3224.00,52000.00,754.00,D,3500.00,,,true,MA,"000123456",48500.00,2425.00,,,,
2026,"5678","98-7654321","Ridgeline Sample Co","07030",71200.00,8340.00,76000.00,4712.00,76000.00,1102.00,D,4800.00,DD,9200.00,true,NJ,"112233",40000.00,1200.00,NY,"445566",31200.00,1650.00
A few choices in that header are worth copying. Each column name says which box it holds, so box4_ss_withheld is never confused with Box 4 on another form. Amounts use two decimal places. The IRS instructions tell employers not to use dollar signs and not to omit cents or the decimal point on the form, and the same habit keeps a CSV clean. The SSN column holds only the last four digits, a choice explained under is a W2 CSV safe to email?
Add columns rather than renaming them. If you later need Box 7, Box 8 or Box 14a, append them at the end of the header so older files still line up.
Keeping EIN and ZIP code leading zeros in a W2 CSV
EINs and ZIP codes in a W2 CSV lose their leading zeros when a spreadsheet guesses they are numbers. An EIN such as 04-5551234 or a ZIP code such as 02110 starts with a zero, and a number has no use for one, so the program drops it. The fix is to store and open those columns as text.
Microsoft documents the cause directly. Its support article on keeping leading zeros and large numbers in Excel says "Excel automatically removes leading zeros" and converts long numbers to scientific notation so that formulas can work on them. It also says Excel has a maximum precision of 15 significant digits, which matters for long state employer ID numbers.
There are three layers of defense, and you want all three.
- Write ID columns with a hyphen where the format has one. The IRS instructions give the EIN format as XX-XXXXXXX. A value with a hyphen in it is less likely to be read as a plain number.
- Quote ID fields in the file. RFC 4180 allows any field to be enclosed in double quotes. Quoting alone does not force a type in every program, but it signals text to many importers.
- Open the file through an import step that sets those columns to Text. In Excel, that means the From Text/CSV import with the ID columns changed to Text before loading.
A ZIP code that has already lost its zero can be repaired with a formula that pads it back to five digits, but an EIN that was saved as a number in a CSV and reopened may have lost its hyphen as well. Fixing the source file is safer than patching a damaged copy.
How should a W2 CSV store Box 12 codes and a second state?
A W2 CSV can store Box 12 codes and a second state in two ways: wide columns on one row, or extra rows linked by a form ID. Wide columns suit a sheet a person reads. Extra rows suit a database or a script that loops over items. Both are correct as long as you pick one and keep it.
Box 12 holds coded items such as D for 401(k) elective deferrals and DD for the cost of employer-sponsored health coverage, according to the IRS General Instructions for Forms W-2 and W-3. The instructions say not to enter more than four items in Box 12 on Copy A, and to issue a second Form W-2 when there are more. That limit is why four code-and-amount pairs, 12a through 12d, cover one paper form.
The state lines work the same way. The instructions say Boxes 15 to 20 have room for two states and two localities, and an employer with more than two prepares a second W-2. So a wide layout with state1_ and state2_ columns covers one form, as in the second sample row above.
When to switch to extra rows
Use a long layout when your data has many codes, when new codes appear, as three did for 2026 according to the overview of W2 boxes 12, 13 and 14, or when a script will process each item. A long table might look like this:
form_id,item_type,code_or_state,amount,state_employer_id
w2-0002,box12,D,4800.00,
w2-0002,box12,DD,9200.00,
w2-0002,state,NJ,40000.00,"112233"
w2-0002,state,NY,31200.00,"445566"
In this layout the main CSV keeps one row per form, and a second file holds the repeating items with the form_id linking the two. It never needs a new column when a new code appears.
Whichever layout you choose, never sum a code column without the code beside it. A D amount and a DD amount mean different things, and adding them gives a number nobody can use. For data that will feed code rather than a sheet, nested arrays are the cleaner answer, as the post on the W2 JSON format with arrays for Box 12 and state lines explains.
Opening a W2 CSV in a spreadsheet without mangling it
To open a W2 CSV without mangling it, import the file and set the ID columns to Text before the data loads. Double-clicking a CSV hands every column to the spreadsheet's type guessing, which is how EINs lose zeros, ZIP codes shrink to four digits and long ID numbers turn into scientific notation.
In Excel, Microsoft's article on keeping leading zeros and large numbers gives the steps. Go to the Data tab and choose From Text/CSV. In the preview, choose Edit to open the Query Editor. Select each ID column header, then set Home, Transform, Data Type to Text and choose Replace Current. Finish with Close & Load. The article says refreshing the query applies the same conversion again.
Which columns to set as text in a W-2 file:
employee_ssn_last4, so 0012 stays four digitsemployer_einemployer_zip- every
state*_employer_idcolumn
Leave the amount columns as numbers so they can be totaled. After loading, sort by EIN once and look for any value shorter than ten characters including the hyphen. That quick look catches a column that slipped through as a number.
If you only need to look at the file, not edit it, a plain text editor shows exactly what is in it with no conversion at all. That is the fastest way to confirm whether a zero was lost in the file or only on screen.
Is a W2 CSV safe to email?
A W2 CSV is not safe to email as plain text when it holds full Social Security numbers. It is a readable list of a person's identity, employer and pay, and anyone who sees the attachment can read every value. Mask identifiers first, then send the file encrypted or through a secure portal.
Masking starts with the SSN. The IRS General Instructions for Forms W-2 and W-3 allow employers to truncate the employee's SSN on employee copies, for example to ***-**-1234, though they must show the full number on Copy A for the Social Security Administration. A CSV that is only used for totals or a budget rarely needs more than the last four digits, which is why the sample header above has employee_ssn_last4 instead of a full SSN column.
Encryption comes next. The IRS publication for tax professionals, Publication 4557, Safeguarding Taxpayer Data, tells them to encrypt all sensitive files and emails, especially those holding a taxpayer's personally identifiable information, and to use strong password protections. The same advice is sound for anyone sending a W-2 file to a preparer or a family member.
Before sending, also delete columns the recipient does not need. A preparer may want every box. A lender checking income may need only Box 1 and the employer. Fewer columns mean less to lose if the message goes astray. The accuracy and security category covers SSN masking and data handling in more depth.
Schema Tax masks SSNs and TINs to the last four digits before anything is stored, and its CSV export carries the same masked value, so the file starts out safer to share. The security section on the homepage lists what else it does with your files.