Importance: The 2019 federal Ending the HIV Epidemic initiative requires a vast expansion of access to antiretroviral therapy (ART) and preexposure prophylaxis (PrEP) for HIV treatment and prevention. However, high prices for ART and PrEP can reduce their affordability and use. Medicare covers 1 in 4 persons living with HIV, and the Medicare Part D drug benefit imposes complicated cost-sharing between patients and other stakeholders. Objective: To determine how the Medicare Part D design distributes the cost burden for ART and PrEP between patients, insurance plans, manufacturers, and Medicare. Design and Setting: Nationwide cross-sectional analyses of first quarter 2019 Medicare formulary and pricing files for 3326 Part D plans were performed. These files contain drug benefit data, including prices and cost-sharing requirements. Main Outcomes and Measures: For 18 ART and 2 PrEP regimens, the out-of-pocket costs for patients and the cost borne by plans, manufacturers, and Medicare were projected for 1 year of treatment or prevention under a 2019 standard Medicare Part D insurance plan. Analyses assumed that patients used the ART or PrEP regimen and no other medications. Results: In 2019, ART prices ranged from $24 010 to $46 770 annually (median price, $35 780), with patients projected to pay 9% to 14% of the cost ($3270-$4350), insurance plans 18% to 24% ($5340-$8450), manufacturers 6% to 11% ($2370-$2750), and Medicare 53% to 67% ($12 770-$31 270). The price of PrEP was $20 570 annually, with patients contributing 15% ($2990), insurance plans 22% ($4570), manufacturers 13% ($2750), and Medicare 50% ($10 260). For beneficiaries with low-income subsidies that cover all patient cost-sharing, Medicare would assume 67% to 76% of ART costs and 65% of PrEP costs. Conclusions and Relevance: Medicare Part D mandates universal ART and PrEP coverage, but high prices (>$35 000 annually for ART and>$20 000 annually for PrEP) and the design of Part D can jeopardize affordability for patients and place most of the cost burden on taxpayers. Under a standard Medicare Part D benefit, patients pay $3000 to $4000 out-of-pocket yearly, unless they qualify for low-income subsidies, and half to two-thirds of the cost of ART and PrEP is borne by Medicare rather than insurance plans or manufacturers. To end the HIV epidemic by 2030, it appears that policies must address both high drug prices and revamp Medicare Part D cost-sharing.