An image decoding method performed by an image decoding apparatus, the image decoding method comprising: deriving a L0 prediction sample and a L1 prediction sample of a current block by using motion information of the current block; deriving a gradient for a predetermined area including a current subblock in the current block; deriving motion offset (vx, vy) for the current subblock by using the gradient; deriving a Bi-directional Optical Flow (BDOF) offset by using the gradient and the motion offset; and deriving a prediction sample for the current block by using the L0 prediction sample, the L1 prediction sample of the current block and the BDOF offset, wherein the gradient is derived by right-shifting the L0 prediction sample and the L1 prediction sample of the current block by a first shift, wherein the deriving the motion offset (vx, vy) comprises: deriving a first intermediate parameter diff by subtracting the L1 prediction sample of the current block from the L0 prediction sample of the current block, and deriving second intermediate parameters tempH and tempV by right-shifting the gradient by a third shift, wherein the deriving the first intermediate parameter diff comprises right-shifting the L0 prediction sample and the L1 prediction sample of the current block by a second shift, and wherein the first shift, the second shift and the third shift are set to a fixed value regardless of a bit depth of the current block, wherein a value of the first shift is different from a value of the second shift and a value of the third shift, and wherein a value of the second shift is different from a value of the third shift. deriving a L0 prediction sample and a L1 prediction sample of a current block by using motion information of the current block; deriving a gradient for a predetermined area including a current subblock in the current block; deriving motion offset (vx, vy) for the current subblock by using the gradient; deriving a Bi-directional Optical Flow (BDOF) offset by using the gradient and the motion offset; and deriving a prediction sample for the current block by using the L0 prediction sample, the L1 prediction sample of the current block and the BDOF offset, wherein the gradient is derived by right-shifting the L0 prediction sample and the L1 prediction sample of the current block by a first shift, wherein the deriving the motion offset (vx, vy) comprises: deriving a first intermediate parameter diff by subtracting the L1 prediction sample of the current block from the L0 prediction sample of the current block, and deriving second intermediate parameters tempH and tempV by right-shifting the gradient by a third shift, deriving a first intermediate parameter diff by subtracting the L1 prediction sample of the current block from the L0 prediction sample of the current block, and deriving second intermediate parameters tempH and tempV by right-shifting the gradient by a third shift, wherein the deriving the first intermediate parameter diff comprises right-shifting the L0 prediction sample and the L1 prediction sample of the current block by a second shift, and wherein the first shift, the second shift and the third shift are set to a fixed value regardless of a bit depth of the current block, wherein a value of the first shift is different from a value of the second shift and a value of the third shift, and wherein a value of the second shift is different from a value of the third shift. <EOS>