A washing machine comprising: a main body configured to constitute an exterior of the washing machine and having a laundry port therein; a main door installed in the main body to open and close the laundry port; and a locking device configured to lock or unlock the main door in a state in which the main door is closed; a tub installed inside the main body and configured to accommodate water; a drum rotatably installed inside the tub and configured to accommodate laundry; an auxiliary door installed in the main door and capable of being opened and closed separately from the main door and disposed at an upper portion of the main door at a level higher than the level of water stored in the tub so that, when the auxiliary door is opened or closed during an operation of the washing machine, the water in the tub can be prevented from overflowing and a controller; characterised in that the washing machine further comprises: a door opening and closing sensor detecting opening and closing of the auxiliary door; an auxiliary locking device installed in a body of the main door configured to lock or unlock the auxiliary door in a state in which the auxiliary door is closed; and wherein the controller analyses a signal of the door opening and closing sensor to determine whether the auxiliary door is opened or closed, the controller is configured to lock the auxiliary door and the main door and then unlock the auxiliary door when a locking time of the auxiliary door is counted and a predetermined time elapses, and maintain the locking of the main door, wherein the controller maintains the auxiliary door in an unlocked state during an operation of the washing machine, and when locking conditions of the auxiliary door are detected by at least one detector (100, 102, 104, 106, 108, 109), the controller controls a locking operation of the auxiliary door. a main body configured to constitute an exterior of the washing machine and having a laundry port therein; a main door installed in the main body to open and close the laundry port; and a locking device configured to lock or unlock the main door in a state in which the main door is closed; a tub installed inside the main body and configured to accommodate water; a drum rotatably installed inside the tub and configured to accommodate laundry; an auxiliary door installed in the main door and capable of being opened and closed separately from the main door and disposed at an upper portion of the main door at a level higher than the level of water stored in the tub so that, when the auxiliary door is opened or closed during an operation of the washing machine, the water in the tub can be prevented from overflowing and a controller; characterised in that the washing machine further comprises: a door opening and closing sensor detecting opening and closing of the auxiliary door; an auxiliary locking device installed in a body of the main door configured to lock or unlock the auxiliary door in a state in which the auxiliary door is closed; and wherein the controller analyses a signal of the door opening and closing sensor to determine whether the auxiliary door is opened or closed, the controller is configured to lock the auxiliary door and the main door and then unlock the auxiliary door when a locking time of the auxiliary door is counted and a predetermined time elapses, and maintain the locking of the main door, wherein the controller maintains the auxiliary door in an unlocked state during an operation of the washing machine, and when locking conditions of the auxiliary door are detected by at least one detector (100, 102, 104, 106, 108, 109), the controller controls a locking operation of the auxiliary door. a door opening and closing sensor detecting opening and closing of the auxiliary door; an auxiliary locking device installed in a body of the main door configured to lock or unlock the auxiliary door in a state in which the auxiliary door is closed; and wherein the controller analyses a signal of the door opening and closing sensor to determine whether the auxiliary door is opened or closed, the controller is configured to lock the auxiliary door and the main door and then unlock the auxiliary door when a locking time of the auxiliary door is counted and a predetermined time elapses, and maintain the locking of the main door, wherein the controller maintains the auxiliary door in an unlocked state during an operation of the washing machine, and when locking conditions of the auxiliary door are detected by at least one detector (100, 102, 104, 106, 108, 109), the controller controls a locking operation of the auxiliary door.