SM U-31 or U-XXXI was a U-27 class U-boat or submarine for the Austro-Hungarian Navy. U-31, built by the Hungarian firm of Ganz Danubius at Fiume, was launched in March 1917 and commissioned in April.