A device includes a substrate; a buffer layer; and a device formation layer, wherein the buffer layer is formed by sequentially stacking, a plurality of times, a first nitride-based semiconductor layer made of a material having a lattice constant lower than a lattice constant of a material of the substrate; a first composition graded layer made of a material having a lattice constant gradually higher than the lattice constant of the first nitride-based semiconductor layer in a thickness direction; a second nitride-based semiconductor layer made of a material having a lattice constant higher than the lattice constant of the first nitride-based semiconductor layer; and a second composition graded layer made of a material having a lattice constant gradually lower than the lattice constant of the second nitride-based semiconductor layer in the thickness direction, and the second composition graded layer is thicker than the first composition graded layer.