In 2364, the USS Enterprise-D was hurled 2,700,000 light years, through two galaxies, to the Triangulum Galaxy by the Traveler during warp field tests; after reversing engines, the ship emerged in the vicinity of a giant protostar in the process of formation.
Calculations indicated that a return trip to the Milky Way from Triangulum, using maximum warp speed, would take over three hundred years. A subspace radio message, sent from the Triangulum Galaxy to Starfleet Command, was estimated to have a travel time of fifty-one years set to arrive in the year 2415. (TNG: "Where No One Has Gone Before")
According to the Star Trek Encyclopedia (4th ed., vol. 1, p. 291), the Triangulum Galaxy was the "33rd object in Messier's catalog," hence "M-33". In the real world, the Triangulum galaxy is 2,723,000 light-years from Earth, and is also known as "NGC 598".
With a return trip time of "over three hundred years" using maximum warp, Federation technology had matched that seen of the Kelvan Empire in the Star Trek: The Original Series episode "By Any Other Name". The Kelvans made a voyage from the Andromeda Galaxy to the Milky Way in three centuries; a feat, remarked at in amazement by James T. Kirk who stated that, in the 23rd century, it would have taken a starship "thousands of years" to travel between galaxies.