a reasonable encoding
Before a machine can chew on a graph, a number, or a grammar, the object has to be written down as a string of symbols, because that is all a machine ever sees on its tape. There are many ways to write the same object down, and the choice is not innocent. A reasonable encoding is one that is honest about size: it does not secretly blow the input up or shrink it in a way that distorts the difficulty of the problem. It is the agreed-upon ruler we measure n with.
The classic trap is writing numbers in unary. To encode the number 12 in binary takes about 4 symbols (1100); in unary it takes 12 symbols (111111111111), and a million takes a million symbols. So a unary encoding makes the input size grow like the value N itself, not like log N, which can magically turn an exponential-time method into a 'polynomial-time' one on paper, purely by padding. We rule unary out: a reasonable encoding writes numbers in binary (or any base at least 2), lists graphs by adjacency lists or matrices, and so on. The deep fact that rescues us is that all reasonable encodings of the same object have sizes that are polynomially related to one another, so a problem that is polynomial-time under one reasonable encoding is polynomial-time under all of them.
This is why complexity theory can talk about 'the' time complexity of a problem without obsessing over format. As long as you avoid pathological encodings like unary padding or absurd compression, the class P and the polynomial-time boundary do not depend on the exact way you spell the input. Fixing a reasonable encoding is the quiet first step that makes every later claim about efficiency well defined.
Encode the number 100 in binary as '1100100' (7 symbols) versus unary as a run of 100 ones (100 symbols). An algorithm that loops once per symbol is fast under unary (looks linear in size) but the same loop is exponential in the size of the binary input, because the binary size is only about log 100. Binary is the reasonable choice.
Unary padding fakes efficiency; binary keeps the input size honest at about log N.
All reasonable encodings of the same object are within a polynomial of one another, so P is encoding-independent; only pathological encodings (notably unary) break this, which is exactly why we forbid them.