Schema Tax

W2 Data Extraction: From PDF or Photo to Fields

By Schema TaxPublished Updated

W2 data extraction turns the boxes on a W-2 into named fields you can sort, total and check. You can extract data from a W2 by typing it, by running OCR, or by AI extraction that labels each value. Whichever method you choose, validate the result with rate and pattern checks before anyone relies on it.

Three ways to extract data from a W2: typing, OCR and AI extraction

There are three ways to extract data from a W2: type each box by hand, run optical character recognition (OCR) to get raw text, or use AI extraction that returns each box as a labelled field. They differ in setup time, time per form, and the kind of errors they make.

Typing by hand

Typing needs no tools and works on any W-2 you can see. For one or two forms it is often the fastest choice. The errors are human ones: a transposed pair of digits, a value typed into the next row, a Box 12 entry skipped because it sat at the bottom of the block. Those errors look normal, so nobody notices until a total disagrees.

Time grows in a straight line with the number of forms. A household with two W-2s spends minutes; a preparer with two hundred spends days, and the error rate rises as attention fades.

OCR

OCR converts a picture of the page into text. It is fast and cheap, but its output is a stream of characters, not fields. Someone still has to decide that "52400.00" next to the word "Wages" is Box 1, and that "D" and "3500.00" form one Box 12 entry. OCR also brings its own character errors, explained in W2 OCR misreads: digits, commas and cents.

If the W-2 is a PDF with a text layer, OCR is not needed at all. The text is already there, and the remaining work is matching values to boxes.

AI extraction

AI extraction reads the page as a form. It finds the box labels, pairs each with its value, and returns named fields such as wages, federal income tax withheld and Box 12 entries. It handles payroll templates it has not seen because it reads labels instead of fixed positions.

Its errors are fewer but not zero, so it should come with checks and a review step. The main cost is choosing and trusting a tool. A tool that cannot show which box each value came from is hard to audit.

MethodSetupTime per formTypical error
TypingNoneMinutesTransposed digits, wrong row
OCRLowSeconds, plus mapping workLook-alike characters, lost punctuation
AI extractionChoose a toolSeconds, plus review of flagsOccasional uncertain read, flagged for review

Which W2 data fields are worth extracting?

The W2 data fields worth extracting depend on what the data is for. A tax return needs nearly every box, a household budget needs a handful, and a loan file usually needs income and employer details. Extracting more than you need costs little with software and a lot by hand, so decide before you start typing.

The box labels below come from the IRS General Instructions for Forms W-2 and W-3 (2026). These describe what each box holds; they do not say what you should report.

FieldBoxFor a returnFor a budgetFor a loan file
Employee SSN, maskedaYesNoLast four only
Employer EINbYesNoYes
Employer name and addresscYesName onlyYes
Wages, tips, other compensation1YesYesYes
Federal income tax withheld2YesYesSometimes
Social security wages and tax3, 4YesTax onlySometimes
Medicare wages and tax5, 6YesTax onlySometimes
Social security tips, allocated tips7, 8If presentIf presentIf present
Dependent care benefits10If presentNoNo
Nonqualified plans11If presentNoNo
Box 12 codes and amounts12YesRetirement codesSometimes
Box 13 checkboxes13YesNoNo
Other, and tipped occupation codes14a, 14bIf presentNoNo
State and local lines15 to 20YesTax amountsSometimes

Three fields deserve care whatever the purpose. The EIN is the cleanest key for matching a W-2 to an employer, because names vary between documents. Box 12 entries must be kept as code-and-amount pairs, since an amount without its code has no meaning. State lines must be kept as rows, one state per row, so wages and tax for the same state stay together.

Validating extracted W2 data with rate and pattern checks

Validating extracted W2 data means testing each value against rules the form itself obeys before the data goes anywhere. A wrong digit that passes into a spreadsheet gets summed, copied and filed. A check at extraction time costs nothing and catches the error while the original page is still open.

The W-2 has several built-in rules: the rates, the 2026 wage base and the Medicare threshold set out in the maximum W2 Box 4 Social Security tax for the year, plus the instructions' XX-XXXXXXX format for the EIN, which may never be truncated.

Those rules become a short list of checks you can run on every extracted record:

  1. Box 4 is within a cent or two of 6.2% of Box 3.
  2. Box 4 is no more than $11,439 for 2026.
  3. Box 3 plus Box 7 is no more than $184,500 for 2026.
  4. Box 6 is at least 1.45% of Box 5, and above it only when Box 5 tops $200,000.
  5. The EIN has two digits, a hyphen and seven digits.
  6. The SSN, if present, is masked to its last four digits, such as XXX-XX-1234.
  7. Every Box 12 code appears in the current IRS code list.
  8. Every amount has exactly two digits after the decimal point.
  9. Each state line with wages also has a state code and an employer state ID.

A failed check does not prove the extraction is wrong. A W-2 can contain an employer's own error, and an employee with two jobs can hit the wage base differently on each form. A failed check means a person should compare the value with the page. Passing all nine is strong evidence the extraction matches the form.

Run the checks on the extracted fields, not on the raw text. A check on fields knows that the number it is testing is Box 4. A check on raw text has to guess, which brings back the mapping problem extraction was meant to solve.

W2 data extraction edge cases: W-2c forms, extra Box 12 codes and two states

Some W-2s break a simple W2 data extraction setup that assumes one form, four Box 12 slots and one state. The common cases are corrected forms, more Box 12 entries than expected, and work in more than one state. Each needs a rule decided in advance.

W-2c corrected forms

A Form W-2c corrects a W-2 that was already issued. The IRS instructions describe it as the form used to correct a previously filed W-2, and the current Form W-2c carries a January 2026 revision date. For each box that changed, a W-2c shows the original amount under "Previously reported" and the new one under "Correct information". An extraction that treats it as a regular W-2 will read the old and new values as two separate figures, or add them together.

The rule is to extract a W-2c as its own record type, linked to the original W-2 by employer EIN and tax year, with the corrected values replacing the originals only for the boxes that changed.

More than four Box 12 entries

Copy A, the copy filed with the Social Security Administration, holds four Box 12 items, and the instructions tell employers to issue an additional W-2 for the rest. IRS Publication 1141 lets employee copies show more than four. An extraction can therefore meet five entries on one page, or two pages from one employer that together hold six. Store Box 12 as a list, not as four fixed slots.

The list of codes grows too, as the three codes added for 2026 in the overview of W2 boxes 12, 13 and 14 show, so a validator with a hard-coded older list will reject correct data.

Two or more states

The state and local boxes hold two states and two localities per form, and a third requires a second W-2. Store state lines as a list of rows. When two W-2 pages from one employer share an EIN and year, check whether they are a second form for extra states before treating them as duplicates.

Where should extracted W2 data go next?

Extracted W2 data should go to the format the next person or program reads most easily: a spreadsheet for review and totals, CSV for moving rows between systems, JSON for software, or a preparer with the original forms attached. The choice depends on who uses the numbers, not on the extraction method.

A spreadsheet suits a person who wants to see every form, add totals and spot a value that looks wrong. The layout matters more than the tool; the guide on W2 to Excel with one row per form shows columns that keep Box 12 pairs and state rows usable.

CSV suits a move from one system to another, such as from extraction into an accounting tool. It is plain text, so it keeps exact digits, but it loses formatting and can lose leading zeros in IDs when opened in a spreadsheet.

JSON suits software. Each W-2 becomes one object with named, typed fields, and Box 12 and state lines become nested lists. The post on W2 JSON field names and types sets out a field list. Developers who would rather send a file and receive JSON back can read the tax form API articles.

A preparer usually wants both the data and the original W-2s, so they can check any number against its source. Sending only a spreadsheet removes their ability to verify.

If you plan to build the extraction yourself, the guide to building a W2 parser covers the output shape and a test set.

Extracting W2 data with Schema Tax in five steps

Schema Tax extracts W2 data in five steps: identify, extract, validate, review and export. Each step has one job, and the result keeps every value's box number and field name. The walkthrough below follows one fictional W-2 through all five, with example values only.

The sample is a W-2 from "Example Payroll Co." for a fictional employee whose SSN shows as XXX-XX-1234. It arrives as a phone photo inside a PDF that also holds a 1099-INT.

  1. Identify. The page is classified as a W-2 for tax year 2026, and the 1099-INT page in the same PDF is classified separately.
  2. Extract. Each box is read into a typed field with a fixed name. Box 1 becomes wages of 58,000.00, Box 2 federal income tax withheld of 6,100.00, Box 3 Social Security wages of 61,500.00, Box 4 of 3,813.00, Box 5 of 61,500.00 and Box 6 of 891.75. Box 12 holds D 3,500.00 and DD 7,200.00. One state line shows state wages of 58,000.00.
  3. Validate. Box 4 equals 6.2% of Box 3, Box 6 equals 1.45% of Box 5, and the EIN matches the XX-XXXXXXX pattern.
  4. Review. The photo had glare over Box 12, so the DD amount is flagged on the editable view of the form. You compare it with the page and confirm it.
  5. Export. You download the record as JSON, CSV or Excel.

Fields pulled from the sample

  • Employee SSN, masked to XXX-XX-1234
  • Employer EIN and name
  • Boxes 1 to 6
  • Box 12 entries as code-and-amount pairs (D, DD)
  • Box 13 checkboxes (retirement plan marked)
  • State line: state, employer state ID, state wages, state tax
  • Boxes 7, 8, 10 and 11 (empty on this form)

Box 1 is lower than Box 3 in the sample because of the 401(k) deferral shown as code D. The IRS Box 3 instructions for Form W-2 say elective deferrals are reported in Box 3 "even though the deferrals are not includible in box 1." That difference is expected, so no check flags it.

Schema Tax masks the SSN to its last four digits before storage and does not prepare or file returns. The five steps from paper to checked data are laid out on the homepage. Pricing is per page, with a free tier.

All posts in W-2 Forms