Two islands sit off the south side of Cape Cod and both are close enough to visit for the day, which is why half the people staying on the peninsula end up standing on a ferry dock at some point in the week. Martha's Vineyard is a big island, roughly the size of a small county, with six towns, a year-round population and a working agricultural interior. Nantucket is smaller, flatter and thirty miles out into open Atlantic, and was for a few decades in the early nineteenth century the most important whaling port on earth.
Neither is part of Cape Cod. They are separate places with their own governments, their own economies and, in Nantucket's case, a distinctly separate sense of itself. But the boats to both leave from Cape ports, so the logistics land on this page.
The single most useful thing to know is that almost every problem visitors have with the islands is a transport problem. Not the price of lunch on Nantucket, not the crowds in Edgartown. It is the ferry: the wrong port, the wrong boat, a car that should have stayed on the mainland, a parking lot that is full, a return sailing that leaves ninety minutes earlier than anybody realised, or a fog bank sitting over Nantucket Sound.
Start from the ports. Woods Hole, at the tip of Falmouth on the Upper Cape, is the gateway to Martha's Vineyard, forty-five minutes across Vineyard Sound. Hyannis, in the Mid Cape, is the gateway to Nantucket, either a little over two hours on the traditional vessel or around an hour on the high-speed catamaran. Falmouth Harbour and Harwich Port each run seasonal passenger boats of their own, which are often the easier option if you are staying nearby. Only one operator, the Steamship Authority, carries vehicles to either island.
Then make an honest decision about day-tripping against staying over. A Vineyard day trip from an Upper Cape base is straightforward and genuinely good. A Nantucket day trip from Hyannis works but is tight and expensive, and it works far better on the fast boat than on the slow one. A day trip to either from Wellfleet or Truro is mostly a day in a car, and you would be better off spending it where you are.
One more thing to fold into the plan. If you are already going to the trouble of boarding a boat, remember that a whale-watch trip out of Provincetown is a different and arguably better use of a day on the water, and it does not require a ferry reservation made in March.