I'm not 100% sure if this is possible when working with html design files that get converted to a master page. A code behind is custom code that needs to be deployed to the server. The Design Manager will not package this code when creating a Design Package. Design Packages are Sandbox solutions and Sandbox solutions do not support code behind (anymore).
What can you do?
Download the master page that you already have. (master page, not the html file). Create a Visual Studio farm solution. Add the master page to this solution together with your code-behind. Deploy this package to the server.
Depending on what your requirement are, you can also create a user-control in Visual Studio. Add your code to the suer-control. Deploy this user-control to the server as a farm solution and simply reference this (custom) user-control in your html master page. This way you can continue to work with the html page.