There have been 26 presidents who were senators and/or representatives before becoming President. In addition to being in Congress before becoming president, John Quincy Adams served in the House of Representatives and Andrew Johnson served in the Senate after their presidency.
NOTE: The first five presidents (Washington, Adams, Jefferson, Madison, and Monroe) all served in the Continental Congress prior to the implementation of the current House/Senate design under the Constitution.