It is defined, in general, as the ratio of the maximum stress to the working stress. Mathematically,
Factor of safety = Maximum stress/ Working or design stress
In case of ductile materials e.g. mild steel, where the yield point is clearly defined, the factor of safety is based upon the yield point stress. In such cases,
Factor of safety = Yield point stress/ Working or design stress
In case of brittle materials e.g. cast iron, the yield point is not well defined as for ductile materials. Therefore, the factor of safety for brittle materials is based on ultimate stress.
Factor of safety = Ultimate stress/ Working or design stress
This relation may also be used for ductile materials.
Note: The above relations for factor of safety are for static loading.
Margin of safety
Many government agencies and industries (such as aerospace) require the use of a margin of safety (MoS or M.S.) to describe the ratio of the strength of the structure to the requirements. There are two separate definitions for the margin of safety so care is needed to determine which is being used for a given application. One usage of M.S. is as a measure of capacity like FoS. The other usage of M.S. is as a measure of satisfying design requirements (requirement verification). Margin of safety can be conceptualized (along with the reserve factor explained below) to represent how much of the structure’s total capacity is held “in reserve” during loading.
M.S. as a measure of structural capacity: This definition of margin of safety commonly seen in Textbooks basically says that if the part is loaded to the maximum load it should ever see in service, how many more loads of the same force can it withstand before failing. In effect, this is a measure of excess capacity. If the margin is 0, the part will not take any additional load before it fails, if it is negative the part will fail before reaching its design load in service. If the margin is 1, it can withstand one additional load of equal force to the maximum load it was designed to support (i.e. twice the design load).
A Textbook of Machine Design by R.S.Khurmi and J.K.Gupta