A linear compressor comprising: a cylinder configured to form a compression space; a piston configured to move in the cylinder; a linear motor configured to drive the piston; a voltage detection unit configured to detect the motor voltage applied to the linear motor; a current detection unit configured to sense a current flowing in the linear motor; a relay configured to change an operation mode of the linear motor; a stroke estimation unit configured to compute a stroke estimate using the detected motor current and motor voltage and the motor parameters, the stroke estimation unit configured to compute the stroke estimate using Equation 1 below: x = 1 α ∫ V m − Ri m − L di m dt dt where parameter x is a stroke, α is a motor constant or a counter electromotive force, V m is the motor voltage, i m is the motor current, R is resistance, and L is inductance, and a control unit configured to set at least one parameter associated with the computation of the stroke estimate according to the operation mode changed by the relay, wherein the control unit is configured to: calculate a magnitude of a first current, which is a current flowing in the linear motor before the state of the relay is switched, calculate a magnitude of a second current, which is a current flowing in the linear motor after the state of the relay is switched, compare the magnitude of the first current and the magnitude of the second current to determine whether the relay fails, calculate a ratio between the first current and the second current and to determine that the relay fails when the calculated ratio is in a previously set range, and when the relay fails, reset parameters associated with the computation of the stroke estimate. a cylinder configured to form a compression space; a piston configured to move in the cylinder; a linear motor configured to drive the piston; a voltage detection unit configured to detect the motor voltage applied to the linear motor; a current detection unit configured to sense a current flowing in the linear motor; a relay configured to change an operation mode of the linear motor; a stroke estimation unit configured to compute a stroke estimate using the detected motor current and motor voltage and the motor parameters, the stroke estimation unit configured to compute the stroke estimate using Equation 1 below: x = 1 α ∫ V m − Ri m − L di m dt dt where parameter x is a stroke, α is a motor constant or a counter electromotive force, V m is the motor voltage, i m is the motor current, R is resistance, and L is inductance, and a control unit configured to set at least one parameter associated with the computation of the stroke estimate according to the operation mode changed by the relay, wherein the control unit is configured to: calculate a magnitude of a first current, which is a current flowing in the linear motor before the state of the relay is switched, calculate a magnitude of a second current, which is a current flowing in the linear motor after the state of the relay is switched, compare the magnitude of the first current and the magnitude of the second current to determine whether the relay fails, calculate a ratio between the first current and the second current and to determine that the relay fails when the calculated ratio is in a previously set range, and when the relay fails, reset parameters associated with the computation of the stroke estimate. <EOS>