Whether you’re looking to purchase your first home or to invest in a rental property it is important to consider where you’ll be able to get the most for your money.In May, Realtor.com ranked the U.S. towns where buyers will find the most affordable homes near the water.And while places such as the Hamptons and Malibu aren’t on the list, the beach towns that did rank range from small communities to big cities.To rank each town, Realtor.com aggregated its listing data for every home put on the market in the past year within a one-mile radius of a beach, pulled out the most affordable based on price per square foot, and listed the locations with at least 50 properties.Gulfport, Mississippi, ranked as the cheapest town in which to buy a beach house, according to Realtor.com.Dszc | Istock | Getty ImagesTop 10 cheapest places in the U.S. to buy a beach houseGulfport, Miss.Newport News, Va.New London, Conn.Grand Isle, La.Corpus Christi, TexasAtlantic City, N.J.Navarre, Fla.North Beach, Md.Crescent City, Calif.Shirley, N.Y.Gulfport, Mississippi, is the most affordable town in which to buy a beach house. It is located about halfway between Mississippi’s borders with Louisiana and Alabama and has 26 miles of beach on the Gulf of Mexico.The median sale price of a home within a mile of a beach is $224,900, with the median price per square foot within one mile of a beach at $144, according to Realtor.com.Gulfport offers residents a nice blend of a small-town community and city life. It has become a tourism hub thanks to its fishing tours and boat charters, as well as the fact that it neighbors the casino town of Biloxi.Newport News, Virginia, is home to beaches on both the Atlantic Ocean and the James River.Sherryvsmith_images | Istock | Getty ImagesNewport News, Virginia, ranked second on the list. The city is located on the southern tip of the Virginia peninsula and is about 25 miles from historic Jamestown.The Virginia city is home to beaches on both the Atlantic Ocean and the James River sides. If you’re willing to drive for oceanfront options, Newport News is also about 40 miles from Virginia Beach, the best in the state, according to Realtor.com.In Newport News, the median price within one mile of a beach is $200,000 and the median price per square foot within one mile of a beach is $150.The third place on the list is New London, Connecticut. It has one of the best public beaches in the state, Ocean Beach Park, which sits on the Long Island Sound.The median price within one mile of a beach is $257,000 in New London, while the median price per square foot within one mile of a beach is $175.New London, Connecticut, is a seaport town and has one of the best public beaches in the state, Ocean Beach Park.Denistangneyjr | Istock | Getty Images”New London is like a little gem of affordability,” Keith Turner, a mortgage lender with Homestead Funding, told Realtor.com. “Just look at the prices in some of the cities near here.”Mystic, Connecticut, which is only about a 15-minute drive from New London, has homes near the beach for sale at more than three times as much per square foot, with a median listing home price of $544,500, according to Realtor.com.New London is an authentic seaport town that offers the classic New England vibe without being an overly popular tourist destination.DON’T MISS: Want to be smarter and more successful with your money, work & life? Sign up for our new newsletter!Get CNBC’s free report, 11 Ways to Tell if We’re in a Recession, where Kelly Evans reviews the top indicators that a recession is coming or has already begun.