Health savings accounts (HSAs) allow you to set aside money on a pretax basis to pay for qualified medical expenses. To understand what a qualified medical expense is, it is best to look at what the Internal Revenue Service (IRS) counts as one. The IRS considers certain Medicare premiums as medical expenses.
If you are covered under social security or have paid Medicare tax, you are considered involuntarily enrolled in Medicare A, and cannot count these premiums as a medical expense. If you are not covered under social security and have not paid Medicare tax, you can count these premiums as medical expenses. Therefore, you can use your HSA to pay the premiums in this situation.
The premiums paid in Medicare B and Medicare D are considered a medical expense, and thus you can use your HSA for these expenses.