Among the proponents of the Cape Cod Branch Railroad were Col. Richard Borden of Fall River, who saw the new line as an opportunity to bring more traffic and business through his hometown. He was at one time president of the Bay State Steamboat Company, which together with the Old Colony Railroad formed the noted "Fall River Line". He was later elected president of the Cape Cod Railroad.
On January 26, 1848, the first 14.7-mile segment of the railroad was opened between Middleborough and Wareham. By May 1848 an additional 12.9 miles was opened to Sandwich, enabling unimpeded transit between Boston and Sandwich, thus serving the needs of the Boston & Sandwich Glass Company. In 1853, the extension of the line to Hyannis was started, reaching West Barnstable on December 22, 1853.
On February 22, 1854, the Cape Cod Branch Railroad was renamed the Cape Cod Railroad Company. In the spring of 1854, construction continued, with the railroad reaching Barnstable village May 8, Yarmouth Port May 19, and finally Hyannis on July 8, 1854. Connecting steamboat service to Nantucket commenced from Hyannis in late September and would continue until 1872.
In 1868, the Cape Cod Railroad acquired the Cape Cod Central Railroad (1861–68), which had opened a line from Yarmouth to Orleans in 1865.
In 1871, the Cape Cod Railroad bought the Plymouth and Vineyard Sound Railroad – which had been incorporated in 1861 as the Vineyard Sound Railroad Company intending to build a line from Buzzards Bay to Woods Hole. However, the road to Woods Hole was not completed until July 1872, after the merger with the Cape Cod Railroad. Upon completion of that road, the steamboat service to Nantucket moved to Woods Hole.
By this time, the Cape Cod Railroad had merged with the Old Colony and Newport Railway to form a new company, renamed the Old Colony Railroad. The Cape Cod routes became known as the "Cape Cod Division" of the Old Colony Railroad, with its headquarters in Hyannis.
With much fanfare, the Old Colony Railroad completed the line to Provincetown in July 1873.
The lines of the Cape Cod Railroad became part of the New York, New Haven and Hartford Railroad (NYNH&H) in 1893, when it leased the entire Old Colony Railroad network. The NYNH&H ended daily passenger service to southeastern Massachusetts and Cape Cod in 1959. The railroad did, however, restore the popular seasonal rail service from New York, with connections from Boston, during the 1960 through 1964 summer seasons.
The New Haven's passenger service to Cape Cod was operated under a number of different names, including and Day Cape Codder, the Night Cape Codder, the Neptune, the Islander, and the Flying Dude.