Dana was born in Cambridge, Massachusetts on August 1, 1815, into a family that first settled in colonial America in 1640. As a boy, Dana studied in Cambridgeport under a strict schoolmaster named Samuel Barrett, alongside fellow Cambridge native and future writer James Russell Lowell. Barrett was infamous as a disciplinarian, punishing his students for any infraction by flogging. He also often pulled students by their ears and, on one such occasion, nearly pulled Dana's ear off, causing his father to protest enough that the practice was abolished.

In 1825, Dana enrolled in a private school overseen by Ralph Waldo Emerson, who Dana later mildly praised as "a very pleasant instructor", though he lacked a "system or discipline enough to insure regular and vigorous study". In July 1831, Dana began his studies at Harvard College, though he was suspended for six months before the end of his first year for supporting a student protest. In his junior year, he had a case of measles which also caused ophthalmia and his weakening vision inspired him to take a sea voyage.

Rather than going on a Grand Tour of Europe, he decided to enlist as a common sailor, despite his high-class birth. He left Boston on the brig Pilgrim on August 14, 1834, on a voyage around Cape Horn to the then-remote California, at that time still a part of Mexico. On the 180-ton, 86.5 foot-long Pilgrim, Dana visited a number of settlements in California (including Monterey, San Pedro, San Juan Capistrano, San Diego, Santa Barbara, and Santa Clara and San Francisco). He returned to Massachusetts aboard the ship Alert on September 22, 1836, after two years away from home.

He kept a diary, and after the trip wrote Two Years Before the Mast based on his experiences. The term "before the mast" refers to sailor's quarters — in the forecastle, in the bow of the ship, the officers dwelling near the stern. His writing evidences his later social feeling for the oppressed. After witnessing a flogging on board the Pilgrim, he vowed that he would try to help improve the lot of the common seaman.

After his sea voyage, he returned to Harvard to take up study at its law school, completing his education in 1837. He subsequently became a lawyer, and an expert on maritime law, many times defending common seamen, and wrote The Seaman's Friend, which became a standard reference text on the legal rights and responsibilities of sailors.