Shafranov was born on in the village of Bolshoye Frolovoye, Tetyushsky Uyezd, Kazan Governorate (now in Buinsky District, Tatarstan) to a peasant family. He attended primary school in Tetyushi and left for Tsaritsyn in 1914, where he worked until 1917 as a sailor and helmsman. During the Russian Civil War, he was drafted into the Red Army in October 1919 and was initially sent to the 4th Reserve Rifle Regiment in Kazan as a Red Army man. Shafranov was transferred to the 112th Rifle Regiment of the 13th Rifle Division, with which he fought on the Western Front against Latvian and Finnish troops. From July 1920, he served as a squad leader in the 131st Rifle Regiment of the 15th Rifle Division. With the latter, Shafranov fought against the Army of Wrangel in the Kakhovka bridgehead, the Northern Taurida Offensive, and the Perekop–Chongar Operation.