Tag encoding algorithms