The Model 1861 rifle-musket was the most common U.S. infantry weapon of the Civil War, with about a million made by Springfield Armory and a number of contractors, of whom the Savage Revolving Firearms Company was one. Savage made 25,520 of them at $18 each; yours is standard.
As in most U.S. wars, the Federal army was ill-prepared for war in 1861. Many of its arms were in southern hands, and the two armories (Springfield, Mass., and Harpers Ferry, Virginia) could not make the standard rifle-musket fast enough to supply the huge army required. Further, Harpers Ferry was captured by Virginia troops early in the war and the machinery sent south, so it was lost to the U.S. forever as an arms factory.
The result was that the Union turned to contractors. Most did their best to manufacture a good weapon, but for some their best was not good enough. Others took a lot of money but never produced any guns. Still others produced quality weapons at reasonable prices. Savage, which also made revolvers for the government, was one of the latter. (As far as I can determine, the Edward Savage of the Savage RFA Co. was not related to the Arthur W. Savage who was the principal founder of the Savage Arms Corp., which is still in business.)
Inevitably, there were congressional hearings, investigations by the Secretary of War, accusations of bribes offered and taken, charges of fraud and shoddy goods, etc. Sound familiar?
The gun has significant historical value, especially if there is any documented record of use by a specific unit or in a specific battle. Barring significant association with an individual, value depends on condition. In average good condition (no parts missing or broken, stock not cut, barrel not cut, rifling not reamed out, no heavy rust or deep pits), value runs around $700-800. In fine to excellent condition (seldom seen) with all the above plus a fair amount of original finish on the metal and stock, value can go to $2200+.
The guns were not serial numbered, so the "31" is most likely a unit marking of some sort. Civil War guns were often used in the post-war period by military academies and the like, or even shipped to foreign armies, so the origin of the number probably will never be determined.
The source of most of the above is Flayderman's Guide to Antique American Firearms, which is available through the on-line book dealers and in most book stores.
HTH
Jim