There are some exceptions, including some cases where Medicare Part B (Medical Insurance) may pay for services that you get on board a ship within the territorial waters adjoining the land areas of the U.S. In rare cases, Medicare may pay for services when 1) a medical emergency occurs and the foreign hospital is closer than the nearest U.S. hospital, 2) you are traveling through Canada between Alaska and another state when the medical emergency occurs, or 3) you live in the U.S. but the foreign hospital is closer than nearest U.S. hospital that can treat that condition, regardless of whether or not it is an emergency. Some Medicare supplement policies (C, D, E, F, G, H, I and J) provide Foreign Travel Emergency health care coverage for travel outside the U.S., and some Medicare Advantage plans provide worldwide coverage benefits. Medicare drug plans do not cover drugs purchased outside the U.S.
The 50 states, the District of Columbia, Puerto Rico, the U.S. Virgin Islands, Guam, the Northern Mariana Islands, and American Samoa are considered part of the U.S. Also note that if the services you receive are covered by Medicare (i.e., one of the three conditions in the first paragraph are met), foreign hospitals aren't required to file Medicare claims. You will need to submit an itemized bill to Medicare for your covered doctor, inpatient, and ambulance services.
There are many other specific instances of both coverage and denial of coverage, so it is best to review this explanation on the Medicare website. If you plan on traveling outside of Medicare coverage, you also have the option of purchasing a travel health insurance policy that will cover health care services for a particular foreign trip.