An encoding method of an Ethernet physical layer, comprising: Determining a to-be-encoded first information group, wherein the first information group comprises m characters, m≥2, m≤64 and m is an integer, wherein a character attribute of any character is a data character, a boundary character, or a third-type character, characters of all bytes included in one packet are collectively referred to as data characters, a first byte of a preamble of a packed is marked as a Start, and a next byte after one packet ends is marked as a Terminator, and the Start and the Terminator are referred to as boundary characters and consecutive characters between packets are collectively referred to as third-type characters, one character occupies one byte; detecting a character attribute of each character in the first information group; if the characters in the first information group are all third-type characters, compressing at least one third-type character to make an idle bit appear in the front of the first information group; recording, in the idle bit, that the characters in the first information group are all third-type characters to obtain a second information group, wherein the second information group comprises m bytes; if the first information group comprises n boundary characters, wherein n≥1, and n is an integer, deleting the n boundary characters, and generating a second information group by using the characters, except the n boundary characters, of the first information group, and type information and position information that are of the n boundary characters, wherein the second information group comprises m bytes; and adding header information to the second information group according to a type of the first information group and a correspondence between a prestored type of a information group and a type of header information of the information group, wherein the type of the first information group is determined by the prestored type of the information group and character attributes of the characters in the first information group and wherein if the prestored type of the information group is an all-data-character type and a non-all-data-character type, the header information of the information group comprises at least two types; or if the prestored type of the information group is an all-data-character type, an all-third-type-character type, and a boundary-character-included type, the header information of the information group comprises at least three types. Determining a to-be-encoded first information group, wherein the first information group comprises m characters, m≥2, m≤64 and m is an integer, wherein a character attribute of any character is a data character, a boundary character, or a third-type character, characters of all bytes included in one packet are collectively referred to as data characters, a first byte of a preamble of a packed is marked as a Start, and a next byte after one packet ends is marked as a Terminator, and the Start and the Terminator are referred to as boundary characters and consecutive characters between packets are collectively referred to as third-type characters, one character occupies one byte; detecting a character attribute of each character in the first information group; if the characters in the first information group are all third-type characters, compressing at least one third-type character to make an idle bit appear in the front of the first information group; recording, in the idle bit, that the characters in the first information group are all third-type characters to obtain a second information group, wherein the second information group comprises m bytes; if the first information group comprises n boundary characters, wherein n≥1, and n is an integer, deleting the n boundary characters, and generating a second information group by using the characters, except the n boundary characters, of the first information group, and type information and position information that are of the n boundary characters, wherein the second information group comprises m bytes; and adding header information to the second information group according to a type of the first information group and a correspondence between a prestored type of a information group and a type of header information of the information group, wherein the type of the first information group is determined by the prestored type of the information group and character attributes of the characters in the first information group and wherein if the prestored type of the information group is an all-data-character type and a non-all-data-character type, the header information of the information group comprises at least two types; or if the prestored type of the information group is an all-data-character type, an all-third-type-character type, and a boundary-character-included type, the header information of the information group comprises at least three types.