Repayment is paying back the money you have previous received and have paid the tax. For example, you need to pay back the tuition reimbursement, signing bonus if you leave the company before serving the number of years as required. Another example is to pay back the salary during your temporary disablement when the income was paid later by the insurance company.

Since you have paid the tax on the income at the time when you believe you had the right to claim to the payment, you should be able to recover the tax paid when the income was repaid. You can either claim deduction or credit (if the repayment is more than $3,000) in the year of the repayment according to IRS publication 17.

For W2 repayment, the deduction should be claimed in Schedule A (Itemized Deduction). For repayment of $3,000 or less, enter it in line 23 subject to a threshold of 2% of your adjusted gross income. For repayment over $3,000, enter it in line 28 not subject to a threshold. See effect of Tax Cuts and Jobs Act (TCJA) at the end.

If the repayment is more than $3,000, you can take a credit. The amount of credit is the additional tax you paid in prior year when you included the income which you repaid in a later year. You enter the credit amount in line 73 of form 1040, check the box d, and write “statement <N>” in the space. The statement <N> should include “IRC 1341” and the amount of credit.

The state treatment needs to be handle state by state. California mirror the federal treatment, and you can claim either reduction or credit (if repayment is more than $3,000) independent of the federal selection. As the logic is more complex for natural language, I wrote a section of pseudo code:

IF ( repayment > $3,000 AND CA is "CREDIT" ) {

   IF ( US is "DEDUCTION ) {

      Enter the amount of the federal deduction as a negative amount
      on Schedule CA (540), line 41 ("Other adjustments including
      California lottery losses") to negate the federal deduction
      IF it is carried over to CA.

   Add the credit amount on line 76, the total payment line, of the
   Form 540. To the left of the total, write "IRC 1341" and the
   amount of the credit.
ELSE IF ( CA is "DEDUCTION" ) { /* For any amount of repayment */
   IF ( US is "CREDIT" ) {

      Enter the amount of deduction as a positive number on On CA (540)
      line 41 "Other adjustments including California lottery losses".
      Deductions of $3,000 or less are subject to the 2% federal AGI
   ELSE IF ( US is "DEDUCTION" ) {

      Null /* There is nothing to do as the deduction has been carried over */

VA deduction follows the federal, and credit is also allowed per this letter ruling.

Generally speaking it is better to claim deduction if the current year’s income is higher and to claim credit when prior year’s income is higher. However, you must use itemized deduction to deduct the repayment which may limit your deduction. The ultimate test is to do two returns and compare the result, and do the same for the state as well.

The Tax Cut and Jobs Act eliminated or restricted many itemized deductions in 2018 through 2025, so this route is out.