The invention belongs to the technical field of communication networks, and particularly relates to a flow table optimization method and device based on an SDN, the device comprises a network flow distinguishing module and a flow table processing module, a space threshold value St is set, whether the flow table space occupancy rate exceeds the space threshold value St is judged, if not, the fixed maximum timeout time of a flow table item issued by a controller is Thard, if yes, the flow is detected through the network data flow distinguishing module, whether the flow is larger than the average flow on the link or not is judged, if not, the flow is the mouse flow, and the flow table processing module distributes the timeout time Tms for the mouse flow; if yes, the stream is uploaded to the controller, an elephant stream is selected via screening from the streams uploaded to the controller through a stream table processing module, and timeout time Tel is distributed for the elephant stream; according to the method, the dynamic timeout time can be provided for the elephant flow, the possibility that the elephant flow is cut off is reduced, and the invalid time that the flow table entries occupy the flow table space is reduced, so that the controller load is reduced and the network performance is improved.