An image decoding apparatus comprising: a memory; and at least one processor connected to the memory, the at least one processor configured to: derive a L0 prediction sample and a L1 prediction sample of a current block by using motion information of the current block; derive a gradient for a predetermined area including a current subblock in the current block; derive motion offset (vx, vy) for the current subblock by using the gradient; derive a Bi-directional Optical Flow(BDOF) offset by using the gradient and the motion offset; and derive 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 motion offset (vx, vy) is derived based on: 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, 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. a memory; and at least one processor connected to the memory, the at least one processor configured to: derive a L0 prediction sample and a L1 prediction sample of a current block by using motion information of the current block; derive a gradient for a predetermined area including a current subblock in the current block; derive motion offset (vx, vy) for the current subblock by using the gradient; derive a Bi-directional Optical Flow(BDOF) offset by using the gradient and the motion offset; and derive 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 motion offset (vx, vy) is derived based on: 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, derive a L0 prediction sample and a L1 prediction sample of a current block by using motion information of the current block; derive a gradient for a predetermined area including a current subblock in the current block; derive motion offset (vx, vy) for the current subblock by using the gradient; derive a Bi-directional Optical Flow(BDOF) offset by using the gradient and the motion offset; and derive 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 motion offset (vx, vy) is derived based on: 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, 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, 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.