A very common misconception is that hacking is a crime. This is not always true, however. There are multiple types of hacking and hackers.
White Hat Hacking and Hackers White hat hackers are people who are hired by companies to hack into said company's server(s) or computer(s) to find weaknesses in their security. In other words, they're legally hacking.
Black Hat Hacking and Hackers Black hat hackers are the ones who do illegal hacking. In other words, every last hacker you see in media.
Grey Hat Hackers and Hacking These guys do both sides of hacking and sometimes use illegal hacking to get a white hat result (the white hat example without gaining permission, for example).