1. A computer implemented method for encoding data, the method comprising: in response to a symbol retrieved from an input stream having a sequence of symbols, determining whether a current context can encode the retrieved symbol, wherein the current context is a context associated with a previously emitted symbol from the input stream; emitting a code representing an escape down token in the current context to a code stream if the current context cannot encode the retrieved symbol, wherein the emitted code representing the escape down token is used by a decoder to switch from a higher order context to a lower order context during decoding the code stream; emitting a code representing the retrieved symbol in the current context to the code stream if the current context can encode the retrieved symbol; and optionally escaping to a context having a higher order by emitting a code representing an escape up token in the code stream, wherein a higher order context is a child context to a lower order context as a parent context, wherein the emitted code representing the escape up token is used by the decoder to switch from a lower order context to a higher order context during decoding the code stream.