Provided are: a phenolic resin which is a constituent of an epoxy resin composition that provides a cured product having high heat resistance and high flame retardancy an epoxy resin which is derived from the phenolic resin an epoxy resin composition which contains the phenolic resin or the epoxy resin a prepreg and a cured product of the epoxy resin composition or the prepreg. The phenolic resin is obtained by: firstly obtaining a phenolic compound (a) by a reaction between a phenolic compound represented by formula (1) and a compound represented by formula (2) and then reacting the thus-obtained phenolic compound (a) with a phosphorus-containing compound represented by formula (3). (In the formulae, each of R1-R3 independently represents a hydrogen atom or the like and each of m and k represents an integer of 0-4.)